mirror of
https://github.com/excalidraw/excalidraw.git
synced 2026-12-03 10:00:31 +03:00
* fix: Undeclared dependencies Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * chore: Rationalize package versions Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * chore: Remove old react app remnants Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * feat: Conversion to pnpm Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: Circular deps #0 Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: common package circular dependencies Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * chore: Move history and undo/redo to excalidraw/excalidraw Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * feat: AppState broken up across package boundaries Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: renderElement and binding type racionalization Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: Refactor linearElementEditor to not use types outside the package Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * chore: Do not import self barrel file Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: All circular dependencies except core Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * feat: Bump pnpm to 11 Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: SASS deprecation warnings Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: Polynomial regular expression used on uncontrolled data Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: Vercel deploy Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * feat: excalidraw/history package Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: Polynomial regex in SVG payload decoding Signed-off-by: Mark Tolmacs <mark@lazycat.hu> * fix: emit the internal packages' types from the editor again The editor advertises ./common/*, ./element/*, ./history/*, ./math/* and ./utils/* type subpaths, but without the path aliases tsc treats those packages as external libraries and no longer emits them. Include their sources in the editor's type build, and drop the relative cross-package import that made element/ come out half-emitted. * feat: export the history classes of the editor's API from the entry onIncrement hands out StoreIncrement subclasses and applyDeltas takes StoreDelta, so export them next to CaptureUpdateAction. Hosts then need no dependency of their own on @excalidraw/history. * chore: refuse to publish packages with npm or yarn Only pnpm publish rewrites workspace:* dependencies and applies publishConfig.exports, so a package published with another client can't be installed. --------- Signed-off-by: Mark Tolmacs <mark@lazycat.hu> Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
140 lines
3.6 KiB
JavaScript
140 lines
3.6 KiB
JavaScript
const path = require("path");
|
|
const fs = require("fs");
|
|
const { pathToFileURL } = require("url");
|
|
|
|
const { build } = require("esbuild");
|
|
const { sassPlugin } = require("esbuild-sass-plugin");
|
|
|
|
const { parseEnvVariables } = require("../packages/excalidraw/env.cjs");
|
|
|
|
const ENV_VARS = {
|
|
development: {
|
|
...parseEnvVariables(`${__dirname}/../.env.development`),
|
|
DEV: true,
|
|
},
|
|
production: {
|
|
...parseEnvVariables(`${__dirname}/../.env.production`),
|
|
PROD: true,
|
|
},
|
|
};
|
|
|
|
// Resolve a relative path from the source file's directory
|
|
const resolveRelativePath = (importPath, sourceFile) => {
|
|
const sourceDir = path.dirname(sourceFile);
|
|
const extensions = [".scss", ".css", ""];
|
|
|
|
for (const ext of extensions) {
|
|
const fullPath = path.resolve(sourceDir, importPath + ext);
|
|
if (fs.existsSync(fullPath)) {
|
|
return fullPath;
|
|
}
|
|
// Try with underscore prefix for partials
|
|
const partialPath = path.join(
|
|
path.dirname(fullPath),
|
|
`_${path.basename(fullPath)}`,
|
|
);
|
|
if (fs.existsSync(partialPath)) {
|
|
return partialPath;
|
|
}
|
|
}
|
|
return null;
|
|
};
|
|
|
|
// Precompile function to convert relative paths to absolute paths
|
|
const precompile = (source, sourcePath) => {
|
|
// Match @use and @forward statements with relative paths
|
|
const importRegex = /(@use|@forward)\s+["'](\.[^"']+)["']/g;
|
|
|
|
return source.replace(importRegex, (match, directive, importPath) => {
|
|
const resolvedPath = resolveRelativePath(importPath, sourcePath);
|
|
if (resolvedPath) {
|
|
// Convert to file:// URL format for sass
|
|
const fileUrl = pathToFileURL(resolvedPath).href;
|
|
return `${directive} "${fileUrl}"`;
|
|
}
|
|
return match;
|
|
});
|
|
};
|
|
|
|
// excludes all external dependencies and bundles only the source code
|
|
const getConfig = (outdir) => ({
|
|
outdir,
|
|
bundle: true,
|
|
splitting: true,
|
|
format: "esm",
|
|
packages: "external",
|
|
plugins: [
|
|
sassPlugin({
|
|
precompile,
|
|
}),
|
|
],
|
|
target: "es2020",
|
|
assetNames: "[dir]/[name]",
|
|
chunkNames: "[dir]/[name]-[hash]",
|
|
external: [
|
|
"@excalidraw/common",
|
|
"@excalidraw/element",
|
|
"@excalidraw/history",
|
|
"@excalidraw/math",
|
|
"@excalidraw/fractional-indexing",
|
|
],
|
|
loader: {
|
|
".woff2": "file",
|
|
},
|
|
});
|
|
|
|
function buildDev(config) {
|
|
return build({
|
|
...config,
|
|
sourcemap: true,
|
|
define: {
|
|
"import.meta.env": JSON.stringify(ENV_VARS.development),
|
|
},
|
|
});
|
|
}
|
|
|
|
function buildProd(config) {
|
|
return build({
|
|
...config,
|
|
minify: true,
|
|
define: {
|
|
"import.meta.env": JSON.stringify(ENV_VARS.production),
|
|
},
|
|
});
|
|
}
|
|
|
|
const createESMRawBuild = async () => {
|
|
const chunksConfig = {
|
|
entryPoints: [
|
|
"index.tsx",
|
|
"**/*.chunk.ts",
|
|
// its own entry (`@excalidraw/excalidraw/fonts/google`), so that the
|
|
// catalog stays out of the main bundle and loads without the editor
|
|
// (entries are emitted flat, by name)
|
|
{ in: "fonts/google/index.ts", out: "fonts-google" },
|
|
// The catalog, which the entry above imports on first use. An entry
|
|
// too, so that it's emitted next to it: as a chunk it would land in
|
|
// `fonts/google/`, and `fonts/` is the folder of font files which
|
|
// hosts copy over to serve them themselves
|
|
{ in: "fonts/google/catalog.json", out: "fonts-google-catalog" },
|
|
],
|
|
entryNames: "[name]",
|
|
};
|
|
|
|
// development unminified build with source maps
|
|
await buildDev({
|
|
...getConfig("dist/dev"),
|
|
...chunksConfig,
|
|
});
|
|
|
|
// production minified buld without sourcemaps
|
|
await buildProd({
|
|
...getConfig("dist/prod"),
|
|
...chunksConfig,
|
|
});
|
|
};
|
|
|
|
(async () => {
|
|
await createESMRawBuild();
|
|
})();
|