smartbundle 0.12.4 → 0.13.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__compiled__/cjs/src/PrettyErrors.d.ts +2 -0
- package/__compiled__/cjs/src/PrettyErrors.js +6 -0
- package/__compiled__/cjs/src/PrettyErrors.js.map +1 -0
- package/__compiled__/cjs/src/createViteConfig.d.ts +2 -1
- package/__compiled__/cjs/src/createViteConfig.js +8 -35
- package/__compiled__/cjs/src/createViteConfig.js.map +1 -1
- package/__compiled__/cjs/src/detectModules.js +7 -2
- package/__compiled__/cjs/src/detectModules.js.map +1 -1
- package/__compiled__/cjs/src/index.d.ts +2 -1
- package/__compiled__/cjs/src/index.js +10 -1
- package/__compiled__/cjs/src/index.js.map +1 -1
- package/__compiled__/cjs/src/plugins/babel/index.js +2 -6
- package/__compiled__/cjs/src/plugins/babel/index.js.map +1 -1
- package/__compiled__/cjs/src/plugins/imports/ImportError.d.ts +7 -0
- package/__compiled__/cjs/src/plugins/imports/ImportError.js +35 -0
- package/__compiled__/cjs/src/plugins/imports/ImportError.js.map +1 -0
- package/__compiled__/cjs/src/plugins/imports/index.d.ts +3 -0
- package/__compiled__/cjs/src/plugins/imports/index.js +89 -0
- package/__compiled__/cjs/src/plugins/imports/index.js.map +1 -0
- package/__compiled__/cjs/src/promiseSettledResultErrors.js +1 -1
- package/__compiled__/cjs/src/promiseSettledResultErrors.js.map +1 -1
- package/__compiled__/cjs/src/run.js +13 -4
- package/__compiled__/cjs/src/run.js.map +1 -1
- package/__compiled__/cjs/src/tasks/buildTypesTask/buildTypesTask.js +5 -0
- package/__compiled__/cjs/src/tasks/buildTypesTask/buildTypesTask.js.map +1 -1
- package/__compiled__/cjs/src/tasks/buildTypesTask/callTypescript.js +8 -1
- package/__compiled__/cjs/src/tasks/buildTypesTask/callTypescript.js.map +1 -1
- package/__compiled__/cjs/src/tasks/buildTypesTask/findTypingsNames.d.ts +2 -1
- package/__compiled__/cjs/src/tasks/buildTypesTask/findTypingsNames.js +12 -30
- package/__compiled__/cjs/src/tasks/buildTypesTask/findTypingsNames.js.map +1 -1
- package/__compiled__/cjs/src/tasks/buildTypesTask/findTypingsPackages.d.ts +2 -1
- package/__compiled__/cjs/src/tasks/buildTypesTask/findTypingsPackages.js +13 -13
- package/__compiled__/cjs/src/tasks/buildTypesTask/findTypingsPackages.js.map +1 -1
- package/__compiled__/cjs/src/tasks/viteTask.d.ts +1 -11
- package/__compiled__/cjs/src/tasks/viteTask.js +11 -5
- package/__compiled__/cjs/src/tasks/viteTask.js.map +1 -1
- package/__compiled__/esm/src/PrettyErrors.d.mts +2 -0
- package/__compiled__/esm/src/PrettyErrors.mjs +6 -0
- package/__compiled__/esm/src/PrettyErrors.mjs.map +1 -0
- package/__compiled__/esm/src/createViteConfig.d.mts +2 -1
- package/__compiled__/esm/src/createViteConfig.mjs +4 -31
- package/__compiled__/esm/src/createViteConfig.mjs.map +1 -1
- package/__compiled__/esm/src/detectModules.mjs +7 -2
- package/__compiled__/esm/src/detectModules.mjs.map +1 -1
- package/__compiled__/esm/src/index.d.mts +2 -1
- package/__compiled__/esm/src/index.mjs +10 -1
- package/__compiled__/esm/src/index.mjs.map +1 -1
- package/__compiled__/esm/src/plugins/babel/index.mjs +2 -6
- package/__compiled__/esm/src/plugins/babel/index.mjs.map +1 -1
- package/__compiled__/esm/src/plugins/imports/ImportError.d.mts +7 -0
- package/__compiled__/esm/src/plugins/imports/ImportError.mjs +35 -0
- package/__compiled__/esm/src/plugins/imports/ImportError.mjs.map +1 -0
- package/__compiled__/esm/src/plugins/imports/index.d.mts +3 -0
- package/__compiled__/esm/src/plugins/imports/index.mjs +72 -0
- package/__compiled__/esm/src/plugins/imports/index.mjs.map +1 -0
- package/__compiled__/esm/src/promiseSettledResultErrors.mjs +1 -1
- package/__compiled__/esm/src/promiseSettledResultErrors.mjs.map +1 -1
- package/__compiled__/esm/src/run.mjs +13 -4
- package/__compiled__/esm/src/run.mjs.map +1 -1
- package/__compiled__/esm/src/tasks/buildTypesTask/buildTypesTask.mjs +5 -0
- package/__compiled__/esm/src/tasks/buildTypesTask/buildTypesTask.mjs.map +1 -1
- package/__compiled__/esm/src/tasks/buildTypesTask/callTypescript.mjs +8 -1
- package/__compiled__/esm/src/tasks/buildTypesTask/callTypescript.mjs.map +1 -1
- package/__compiled__/esm/src/tasks/buildTypesTask/findTypingsNames.d.mts +2 -1
- package/__compiled__/esm/src/tasks/buildTypesTask/findTypingsNames.mjs +3 -4
- package/__compiled__/esm/src/tasks/buildTypesTask/findTypingsNames.mjs.map +1 -1
- package/__compiled__/esm/src/tasks/buildTypesTask/findTypingsPackages.d.mts +2 -1
- package/__compiled__/esm/src/tasks/buildTypesTask/findTypingsPackages.mjs +5 -4
- package/__compiled__/esm/src/tasks/buildTypesTask/findTypingsPackages.mjs.map +1 -1
- package/__compiled__/esm/src/tasks/viteTask.d.mts +1 -11
- package/__compiled__/esm/src/tasks/viteTask.mjs +11 -5
- package/__compiled__/esm/src/tasks/viteTask.mjs.map +1 -1
- package/package.json +2 -1
@@ -50,12 +50,8 @@ function babelPlugin({
|
|
50
50
|
};
|
51
51
|
},
|
52
52
|
buildEnd(error) {
|
53
|
-
if (
|
54
|
-
|
55
|
-
okLog("Babel");
|
56
|
-
}
|
57
|
-
} else {
|
58
|
-
this.error(error);
|
53
|
+
if (modules.babel && hasBabelConfig) {
|
54
|
+
okLog("Babel");
|
59
55
|
}
|
60
56
|
}
|
61
57
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../../../../src/plugins/babel/index.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\nimport * as path from \"node:path\";\nimport { findBabelConfig } from \"./findBabelConfig.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\nimport { type DetectedModules } from \"../../detectModules.js\";\nimport { okLog } from \"../../log.js\";\n\ntype BabelPluginOptions = {\n packageJson: PackageJson;\n dirs: Dirs;\n modules: DetectedModules;\n};\n\nexport function babelPlugin({\n packageJson,\n dirs,\n modules,\n}: BabelPluginOptions): Plugin {\n let hasBabelConfig = false;\n\n return {\n name: \"smartbundle:babel\",\n async buildStart() {\n hasBabelConfig = await findBabelConfig(dirs.sourceDir, packageJson);\n if (modules.babel && !hasBabelConfig) {\n this.warn(\n \"We have found a @babel/core package, but config was not found. It could be a bug\",\n );\n } else if (!modules.babel && hasBabelConfig) {\n this.error(\n new Error(\n \"We have found a babel config. Please install @babel/core to devDeps or remove the config file\",\n ),\n );\n }\n },\n async transform(code, id) {\n if (!modules.babel || !hasBabelConfig) {\n return null;\n }\n\n const extname = path.extname(id);\n if (![\".js\", \".ts\"].includes(extname)) {\n return null;\n }\n\n const map = this.getCombinedSourcemap();\n\n const result = await modules.babel.transformAsync(code, {\n filename: id,\n sourceMaps: true,\n inputSourceMap: map,\n });\n\n if (!result?.code) {\n throw new Error(\"Babel transformation failed\");\n }\n\n return {\n code: result.code,\n map: result.map,\n };\n },\n buildEnd(error) {\n if (
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../../../../src/plugins/babel/index.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\nimport * as path from \"node:path\";\nimport { findBabelConfig } from \"./findBabelConfig.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\nimport { type DetectedModules } from \"../../detectModules.js\";\nimport { okLog } from \"../../log.js\";\n\ntype BabelPluginOptions = {\n packageJson: PackageJson;\n dirs: Dirs;\n modules: DetectedModules;\n};\n\nexport function babelPlugin({\n packageJson,\n dirs,\n modules,\n}: BabelPluginOptions): Plugin {\n let hasBabelConfig = false;\n\n return {\n name: \"smartbundle:babel\",\n async buildStart() {\n hasBabelConfig = await findBabelConfig(dirs.sourceDir, packageJson);\n if (modules.babel && !hasBabelConfig) {\n this.warn(\n \"We have found a @babel/core package, but config was not found. It could be a bug\",\n );\n } else if (!modules.babel && hasBabelConfig) {\n this.error(\n new Error(\n \"We have found a babel config. Please install @babel/core to devDeps or remove the config file\",\n ),\n );\n }\n },\n async transform(code, id) {\n if (!modules.babel || !hasBabelConfig) {\n return null;\n }\n\n const extname = path.extname(id);\n if (![\".js\", \".ts\"].includes(extname)) {\n return null;\n }\n\n const map = this.getCombinedSourcemap();\n\n const result = await modules.babel.transformAsync(code, {\n filename: id,\n sourceMaps: true,\n inputSourceMap: map,\n });\n\n if (!result?.code) {\n throw new Error(\"Babel transformation failed\");\n }\n\n return {\n code: result.code,\n map: result.map,\n };\n },\n buildEnd(error) {\n if (modules.babel && hasBabelConfig) {\n okLog(\"Babel\");\n }\n },\n };\n}\n"],"names":[],"mappings":";;;;;;;AAcO,SAAS,YAAY;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AACF,GAA+B;AAC7B,MAAI,iBAAiB;AAEd,SAAA;AAAA,IACL,MAAM;AAAA,IACN,MAAM,aAAa;AACjB,uBAAiB,MAAM,gBAAgB,KAAK,WAAW,WAAW;AAC9D,UAAA,QAAQ,SAAS,CAAC,gBAAgB;AAC/B,aAAA;AAAA,UACH;AAAA,QACF;AAAA,MACS,WAAA,CAAC,QAAQ,SAAS,gBAAgB;AACtC,aAAA;AAAA,UACH,IAAI;AAAA,YACF;AAAA,UAAA;AAAA,QAEJ;AAAA,MAAA;AAAA,IAEJ;AAAA,IACA,MAAM,UAAU,MAAM,IAAI;AACxB,UAAI,CAAC,QAAQ,SAAS,CAAC,gBAAgB;AAC9B,eAAA;AAAA,MAAA;AAGH,YAAA,UAAU,KAAK,QAAQ,EAAE;AAC/B,UAAI,CAAC,CAAC,OAAO,KAAK,EAAE,SAAS,OAAO,GAAG;AAC9B,eAAA;AAAA,MAAA;AAGH,YAAA,MAAM,KAAK,qBAAqB;AAEtC,YAAM,SAAS,MAAM,QAAQ,MAAM,eAAe,MAAM;AAAA,QACtD,UAAU;AAAA,QACV,YAAY;AAAA,QACZ,gBAAgB;AAAA,MAAA,CACjB;AAEG,UAAA,EAAC,iCAAQ,OAAM;AACX,cAAA,IAAI,MAAM,6BAA6B;AAAA,MAAA;AAGxC,aAAA;AAAA,QACL,MAAM,OAAO;AAAA,QACb,KAAK,OAAO;AAAA,MACd;AAAA,IACF;AAAA,IACA,SAAS,OAAO;AACV,UAAA,QAAQ,SAAS,gBAAgB;AACnC,cAAM,OAAO;AAAA,MAAA;AAAA,IACf;AAAA,EAEJ;AACF;"}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { PrettyError } from "../../PrettyErrors.js";
|
2
|
+
export declare class ImportError extends PrettyError {
|
3
|
+
private importName;
|
4
|
+
private path;
|
5
|
+
private constructor();
|
6
|
+
static create(importName: string, path: string | undefined, fsReadFile: typeof import("fs/promises").readFile): Promise<ImportError>;
|
7
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { PrettyError } from "../../PrettyErrors.mjs";
|
2
|
+
class ImportError extends PrettyError {
|
3
|
+
constructor(importName, path) {
|
4
|
+
super(
|
5
|
+
`ImportError: The "${importName}" library is marked as an optional dependency.
|
6
|
+
It cannot be imported directly in:
|
7
|
+
"${path ?? "unknown path"}"
|
8
|
+
|
9
|
+
To resolve this, consider:
|
10
|
+
1. Using a type import (e.g., 'import type').
|
11
|
+
2. Dynamically importing the library (e.g., 'await import("${importName}")').
|
12
|
+
|
13
|
+
This ensures compatibility with environments where "${importName}" is not installed.`
|
14
|
+
);
|
15
|
+
this.importName = importName;
|
16
|
+
this.path = path;
|
17
|
+
}
|
18
|
+
static async create(importName, path, fsReadFile) {
|
19
|
+
if (!path) {
|
20
|
+
return new ImportError(importName, path);
|
21
|
+
}
|
22
|
+
const content = await fsReadFile(path, "utf-8");
|
23
|
+
const lines = content.split("\n");
|
24
|
+
const affectedLine = lines.findIndex((line) => line.includes(importName));
|
25
|
+
const error = new ImportError(importName, path);
|
26
|
+
error.stack = `ImportError: you cannot import ${importName} because it marked as optional inside package.json
|
27
|
+
|
28
|
+
at ${path}:${affectedLine + 1}:0`;
|
29
|
+
return error;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
export {
|
33
|
+
ImportError
|
34
|
+
};
|
35
|
+
//# sourceMappingURL=ImportError.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ImportError.mjs","sources":["../../../../../../src/plugins/imports/ImportError.ts"],"sourcesContent":["import { PrettyError } from \"../../PrettyErrors.js\";\n\nexport class ImportError extends PrettyError {\n private constructor(\n private importName: string,\n private path: string | undefined,\n ) {\n super(\n `ImportError: The \"${importName}\" library is marked as an optional dependency.\\n` +\n `It cannot be imported directly in:\\n` +\n ` \"${path ?? \"unknown path\"}\"\\n\\n` +\n `To resolve this, consider:\\n` +\n `1. Using a type import (e.g., 'import type').\\n` +\n `2. Dynamically importing the library (e.g., 'await import(\"${importName}\")').\\n\\n` +\n `This ensures compatibility with environments where \"${importName}\" is not installed.`,\n );\n }\n\n static async create(\n importName: string,\n path: string | undefined,\n fsReadFile: typeof import(\"fs/promises\").readFile,\n ) {\n if (!path) {\n return new ImportError(importName, path);\n }\n const content = await fsReadFile(path, \"utf-8\");\n const lines = content.split(\"\\n\");\n\n const affectedLine = lines.findIndex((line) => line.includes(importName));\n\n const error = new ImportError(importName, path);\n error.stack = `ImportError: you cannot import ${importName} because it marked as optional inside package.json \\n\n at ${path}:${affectedLine + 1}:0`;\n\n return error;\n }\n}\n"],"names":[],"mappings":";AAEO,MAAM,oBAAoB,YAAY;AAAA,EACnC,YACE,YACA,MACR;AACA;AAAA,MACE,qBAAqB,UAAU;AAAA;AAAA,KAEvB,QAAQ,cAAc;AAAA;AAAA;AAAA;AAAA,6DAGkC,UAAU;AAAA;AAAA,sDACjB,UAAU;AAAA,IACrE;AAXQ,SAAA,aAAA;AACA,SAAA,OAAA;AAAA,EAAA;AAAA,EAaV,aAAa,OACX,YACA,MACA,YACA;AACA,QAAI,CAAC,MAAM;AACF,aAAA,IAAI,YAAY,YAAY,IAAI;AAAA,IAAA;AAEzC,UAAM,UAAU,MAAM,WAAW,MAAM,OAAO;AACxC,UAAA,QAAQ,QAAQ,MAAM,IAAI;AAE1B,UAAA,eAAe,MAAM,UAAU,CAAC,SAAS,KAAK,SAAS,UAAU,CAAC;AAExE,UAAM,QAAQ,IAAI,YAAY,YAAY,IAAI;AACxC,UAAA,QAAQ,kCAAkC,UAAU;AAAA;AAAA,SACrD,IAAI,IAAI,eAAe,CAAC;AAEtB,WAAA;AAAA,EAAA;AAEX;"}
|
@@ -0,0 +1,72 @@
|
|
1
|
+
import { ImportError } from "./ImportError.mjs";
|
2
|
+
import * as fs from "node:fs/promises";
|
3
|
+
function isNodeModule(id) {
|
4
|
+
return id.startsWith("node:");
|
5
|
+
}
|
6
|
+
function importsPlugin(packageJson, test) {
|
7
|
+
var _a, _b;
|
8
|
+
if (test) {
|
9
|
+
return {
|
10
|
+
name: "smartbundle:imports"
|
11
|
+
};
|
12
|
+
}
|
13
|
+
const dynamicDeps = /* @__PURE__ */ new Set();
|
14
|
+
const staticDeps = /* @__PURE__ */ new Set();
|
15
|
+
for (const dep of Object.keys(packageJson.dependencies ?? {})) {
|
16
|
+
dynamicDeps.add(dep);
|
17
|
+
staticDeps.add(dep);
|
18
|
+
}
|
19
|
+
for (const dep of Object.keys(packageJson.peerDependencies ?? {})) {
|
20
|
+
if (!((_b = (_a = packageJson.peerDependenciesMeta) == null ? void 0 : _a[dep]) == null ? void 0 : _b.optional)) {
|
21
|
+
staticDeps.add(dep);
|
22
|
+
}
|
23
|
+
dynamicDeps.add(dep);
|
24
|
+
}
|
25
|
+
for (const dep of Object.keys(packageJson.optionalDependencies ?? {})) {
|
26
|
+
dynamicDeps.add(dep);
|
27
|
+
}
|
28
|
+
dynamicDeps.add(packageJson.name);
|
29
|
+
staticDeps.add(packageJson.name);
|
30
|
+
function createDepResolver(depsSet) {
|
31
|
+
return (id) => {
|
32
|
+
const segments = id.split("/");
|
33
|
+
let current = "";
|
34
|
+
for (const segment of segments) {
|
35
|
+
current += segment;
|
36
|
+
if (depsSet.has(current)) {
|
37
|
+
return true;
|
38
|
+
}
|
39
|
+
current += "/";
|
40
|
+
}
|
41
|
+
return false;
|
42
|
+
};
|
43
|
+
}
|
44
|
+
const dynamicDepResolver = createDepResolver(dynamicDeps);
|
45
|
+
const staticDepResolver = createDepResolver(staticDeps);
|
46
|
+
return {
|
47
|
+
name: "smartbundle:imports",
|
48
|
+
enforce: "pre",
|
49
|
+
async resolveId(id, importer) {
|
50
|
+
if (isNodeModule(id) || staticDepResolver(id)) {
|
51
|
+
return false;
|
52
|
+
}
|
53
|
+
if (dynamicDepResolver(id)) {
|
54
|
+
this.error(await ImportError.create(id, importer, fs.readFile));
|
55
|
+
}
|
56
|
+
return null;
|
57
|
+
},
|
58
|
+
resolveDynamicImport(id) {
|
59
|
+
if (typeof id !== "string") {
|
60
|
+
return null;
|
61
|
+
}
|
62
|
+
if (isNodeModule(id) || dynamicDepResolver(id)) {
|
63
|
+
return false;
|
64
|
+
}
|
65
|
+
return null;
|
66
|
+
}
|
67
|
+
};
|
68
|
+
}
|
69
|
+
export {
|
70
|
+
importsPlugin
|
71
|
+
};
|
72
|
+
//# sourceMappingURL=index.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../../../../src/plugins/imports/index.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\nimport type { PackageJson } from \"../../packageJson.js\";\nimport { ImportError } from \"./ImportError.js\";\nimport * as fs from \"node:fs/promises\";\n\nfunction isNodeModule(id: string) {\n return id.startsWith(\"node:\");\n}\n\nexport function importsPlugin(\n packageJson: PackageJson,\n test?: boolean,\n): Plugin {\n if (test) {\n return {\n name: \"smartbundle:imports\",\n };\n }\n\n const dynamicDeps = new Set<string>();\n const staticDeps = new Set<string>();\n for (const dep of Object.keys(packageJson.dependencies ?? {})) {\n dynamicDeps.add(dep);\n staticDeps.add(dep);\n }\n for (const dep of Object.keys(packageJson.peerDependencies ?? {})) {\n if (!packageJson.peerDependenciesMeta?.[dep]?.optional) {\n staticDeps.add(dep);\n }\n dynamicDeps.add(dep);\n }\n for (const dep of Object.keys(packageJson.optionalDependencies ?? {})) {\n dynamicDeps.add(dep);\n }\n dynamicDeps.add(packageJson.name);\n staticDeps.add(packageJson.name);\n\n function createDepResolver(depsSet: Set<string>) {\n return (id: string) => {\n const segments = id.split(\"/\");\n let current = \"\";\n for (const segment of segments) {\n current += segment;\n // import {} from \"a/b/c/d\"; case\n if (depsSet.has(current)) {\n return true;\n }\n current += \"/\";\n }\n return false;\n };\n }\n\n const dynamicDepResolver = createDepResolver(dynamicDeps);\n const staticDepResolver = createDepResolver(staticDeps);\n return {\n name: \"smartbundle:imports\",\n enforce: \"pre\",\n async resolveId(id, importer) {\n if (isNodeModule(id) || staticDepResolver(id)) {\n return false;\n }\n if (dynamicDepResolver(id)) {\n this.error(await ImportError.create(id, importer, fs.readFile));\n }\n return null;\n },\n resolveDynamicImport(id) {\n if (typeof id !== \"string\") {\n return null;\n }\n if (isNodeModule(id) || dynamicDepResolver(id)) {\n return false;\n }\n\n return null;\n },\n };\n}\n"],"names":[],"mappings":";;AAKA,SAAS,aAAa,IAAY;AACzB,SAAA,GAAG,WAAW,OAAO;AAC9B;AAEgB,SAAA,cACd,aACA,MACQ;;AACR,MAAI,MAAM;AACD,WAAA;AAAA,MACL,MAAM;AAAA,IACR;AAAA,EAAA;AAGI,QAAA,kCAAkB,IAAY;AAC9B,QAAA,iCAAiB,IAAY;AACnC,aAAW,OAAO,OAAO,KAAK,YAAY,gBAAgB,CAAA,CAAE,GAAG;AAC7D,gBAAY,IAAI,GAAG;AACnB,eAAW,IAAI,GAAG;AAAA,EAAA;AAEpB,aAAW,OAAO,OAAO,KAAK,YAAY,oBAAoB,CAAA,CAAE,GAAG;AACjE,QAAI,GAAC,uBAAY,yBAAZ,mBAAmC,SAAnC,mBAAyC,WAAU;AACtD,iBAAW,IAAI,GAAG;AAAA,IAAA;AAEpB,gBAAY,IAAI,GAAG;AAAA,EAAA;AAErB,aAAW,OAAO,OAAO,KAAK,YAAY,wBAAwB,CAAA,CAAE,GAAG;AACrE,gBAAY,IAAI,GAAG;AAAA,EAAA;AAET,cAAA,IAAI,YAAY,IAAI;AACrB,aAAA,IAAI,YAAY,IAAI;AAE/B,WAAS,kBAAkB,SAAsB;AAC/C,WAAO,CAAC,OAAe;AACf,YAAA,WAAW,GAAG,MAAM,GAAG;AAC7B,UAAI,UAAU;AACd,iBAAW,WAAW,UAAU;AACnB,mBAAA;AAEP,YAAA,QAAQ,IAAI,OAAO,GAAG;AACjB,iBAAA;AAAA,QAAA;AAEE,mBAAA;AAAA,MAAA;AAEN,aAAA;AAAA,IACT;AAAA,EAAA;AAGI,QAAA,qBAAqB,kBAAkB,WAAW;AAClD,QAAA,oBAAoB,kBAAkB,UAAU;AAC/C,SAAA;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,MAAM,UAAU,IAAI,UAAU;AAC5B,UAAI,aAAa,EAAE,KAAK,kBAAkB,EAAE,GAAG;AACtC,eAAA;AAAA,MAAA;AAEL,UAAA,mBAAmB,EAAE,GAAG;AACrB,aAAA,MAAM,MAAM,YAAY,OAAO,IAAI,UAAU,GAAG,QAAQ,CAAC;AAAA,MAAA;AAEzD,aAAA;AAAA,IACT;AAAA,IACA,qBAAqB,IAAI;AACnB,UAAA,OAAO,OAAO,UAAU;AACnB,eAAA;AAAA,MAAA;AAET,UAAI,aAAa,EAAE,KAAK,mBAAmB,EAAE,GAAG;AACvC,eAAA;AAAA,MAAA;AAGF,aAAA;AAAA,IAAA;AAAA,EAEX;AACF;"}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
function promiseSettledResultErrors(results) {
|
2
2
|
const errors = [];
|
3
3
|
for (const result of results) {
|
4
|
-
if (result
|
4
|
+
if (Array.isArray(result)) {
|
5
5
|
errors.push(promiseSettledResultErrors(result));
|
6
6
|
} else if (result.status === "rejected") {
|
7
7
|
errors.push(result.reason);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"promiseSettledResultErrors.mjs","sources":["../../../../src/promiseSettledResultErrors.ts"],"sourcesContent":["type Hierarchy = Array<PromiseSettledResult<any> | Hierarchy>;\n\nexport function promiseSettledResultErrors<H extends Hierarchy>(results: H) {\n const errors: Array<any> = [];\n for (const result of results) {\n if (result
|
1
|
+
{"version":3,"file":"promiseSettledResultErrors.mjs","sources":["../../../../src/promiseSettledResultErrors.ts"],"sourcesContent":["type Hierarchy = Array<PromiseSettledResult<any> | Hierarchy>;\n\nexport function promiseSettledResultErrors<H extends Hierarchy>(results: H) {\n const errors: Array<any> = [];\n for (const result of results) {\n if (Array.isArray(result)) {\n errors.push(promiseSettledResultErrors(result));\n } else if (result.status === \"rejected\") {\n errors.push(result.reason);\n }\n }\n return errors.flat(Infinity);\n}\n"],"names":[],"mappings":"AAEO,SAAS,2BAAgD,SAAY;AAC1E,QAAM,SAAqB,CAAC;AAC5B,aAAW,UAAU,SAAS;AACxB,QAAA,MAAM,QAAQ,MAAM,GAAG;AAClB,aAAA,KAAK,2BAA2B,MAAM,CAAC;AAAA,IAAA,WACrC,OAAO,WAAW,YAAY;AAChC,aAAA,KAAK,OAAO,MAAM;AAAA,IAAA;AAAA,EAC3B;AAEK,SAAA,OAAO,KAAK,QAAQ;AAC7B;"}
|
@@ -1,10 +1,19 @@
|
|
1
1
|
import { args } from "./args.mjs";
|
2
2
|
import { run } from "./index.mjs";
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
import { PrettyError } from "./PrettyErrors.mjs";
|
4
|
+
import { Youch } from "youch";
|
5
|
+
const youch = new Youch();
|
6
|
+
(async () => {
|
7
|
+
const res = await run(args);
|
8
|
+
if (!res.error) {
|
9
|
+
return;
|
10
|
+
}
|
11
|
+
for (const error of res.errors) {
|
12
|
+
if (!(error instanceof PrettyError)) {
|
6
13
|
console.error("\x1B[31m[ERROR]", error, "\x1B[0m");
|
14
|
+
continue;
|
7
15
|
}
|
16
|
+
console.error(await youch.toANSI(error));
|
8
17
|
}
|
9
|
-
});
|
18
|
+
})();
|
10
19
|
//# sourceMappingURL=run.mjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"run.mjs","sources":["../../../../src/run.ts"],"sourcesContent":["import { args } from \"./args.js\";\nimport { run } from \"./index.js\";\n\
|
1
|
+
{"version":3,"file":"run.mjs","sources":["../../../../src/run.ts"],"sourcesContent":["import { args } from \"./args.js\";\nimport { run } from \"./index.js\";\nimport { PrettyError } from \"./PrettyErrors.js\";\nimport { Youch } from \"youch\";\n\nconst youch = new Youch();\n\n(async () => {\n const res = await run(args);\n\n if (!res.error) {\n return;\n }\n\n for (const error of res.errors) {\n if (!(error instanceof PrettyError)) {\n console.error(\"\\x1b[31m[ERROR]\", error, \"\\x1b[0m\");\n continue;\n }\n\n console.error(await youch.toANSI(error));\n }\n})();\n"],"names":[],"mappings":";;;;AAKA,MAAM,QAAQ,IAAI,MAAM;AAAA,CAEvB,YAAY;AACL,QAAA,MAAM,MAAM,IAAI,IAAI;AAEtB,MAAA,CAAC,IAAI,OAAO;AACd;AAAA,EAAA;AAGS,aAAA,SAAS,IAAI,QAAQ;AAC1B,QAAA,EAAE,iBAAiB,cAAc;AAC3B,cAAA,MAAM,mBAAmB,OAAO,SAAS;AACjD;AAAA,IAAA;AAGF,YAAQ,MAAM,MAAM,MAAM,OAAO,KAAK,CAAC;AAAA,EAAA;AAE3C,GAAG;"}
|
@@ -18,6 +18,11 @@ async function buildTypesTask({
|
|
18
18
|
const reversedEntrypoints = reverseMap(entrypoints);
|
19
19
|
const entrypointToEsDtsMap = /* @__PURE__ */ new Map();
|
20
20
|
const entrypointToCjsDtsMap = /* @__PURE__ */ new Map();
|
21
|
+
if (tsEntrypoints.length > 0 && modules.ts == null) {
|
22
|
+
throw new Error(
|
23
|
+
'smartbundle found the .ts entrypoint but required "typescript" to build .d.ts files. Please install the "typescript" dependency.'
|
24
|
+
);
|
25
|
+
}
|
21
26
|
if (tsEntrypoints.length === 0 || modules.ts == null) {
|
22
27
|
return { entrypointToEsDtsMap, entrypointToCjsDtsMap };
|
23
28
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buildTypesTask.mjs","sources":["../../../../../../src/tasks/buildTypesTask/buildTypesTask.ts"],"sourcesContent":["import { callTypescript } from \"./callTypescript.js\";\nimport { reverseMap } from \"../utils.js\";\nimport { okLog } from \"../../log.js\";\nimport type { DetectedModules } from \"../../detectModules.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesTaskOption = {\n entrypoints: Map<string, string>;\n dirs: Dirs;\n modules: DetectedModules;\n packageJson: PackageJson;\n};\n\nexport async function buildTypesTask({\n entrypoints,\n dirs,\n packageJson,\n modules,\n}: BuildTypesTaskOption) {\n const { outDir } = dirs;\n const tsEntrypoints = [...entrypoints.values()].filter((entry) =>\n entry.endsWith(\".ts\"),\n );\n const reversedEntrypoints = reverseMap(entrypoints);\n\n const entrypointToEsDtsMap = new Map<string, string>();\n const entrypointToCjsDtsMap = new Map<string, string>();\n if (tsEntrypoints.length === 0 || modules.ts == null) {\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n }\n\n const dtsMap = await callTypescript({\n ts: modules.ts,\n dirs,\n packageJson,\n tsEntrypoints,\n outDir,\n });\n\n for (const [source, dts] of dtsMap.sourceToEsmDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToEsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n for (const [source, dts] of dtsMap.sourceToCjsDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToCjsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n okLog(\".d.ts\");\n\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n}\n"],"names":["entrypoints"],"mappings":";;;;;;;AAcA,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACjB,QAAA,EAAE,WAAW;AACnB,QAAM,gBAAgB,CAAC,GAAG,YAAY,OAAA,CAAQ,EAAE;AAAA,IAAO,CAAC,UACtD,MAAM,SAAS,KAAK;AAAA,EACtB;AACM,QAAA,sBAAsB,WAAW,WAAW;AAE5C,QAAA,2CAA2B,IAAoB;AAC/C,QAAA,4CAA4B,IAAoB;AACtD,MAAI,cAAc,WAAW,KAAK,QAAQ,MAAM,MAAM;AAC7C,WAAA,EAAE,sBAAsB,sBAAsB;AAAA,EAAA;AAGjD,QAAA,SAAS,MAAM,eAAe;AAAA,IAClC,IAAI,QAAQ;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAED,aAAW,CAAC,QAAQ,GAAG,KAAK,OAAO,mBAAmB;AAC9CA,UAAAA,eAAc,oBAAoB,IAAI,MAAM;AAClD,QAAIA,cAAa;AACf,iBAAW,cAAcA,cAAa;AACf,6BAAA,IAAI,YAAY,GAAG;AAAA,MAAA;AAAA,IAC1C;AAAA,EACF;AAGF,aAAW,CAAC,QAAQ,GAAG,KAAK,OAAO,mBAAmB;AAC9CA,UAAAA,eAAc,oBAAoB,IAAI,MAAM;AAClD,QAAIA,cAAa;AACf,iBAAW,cAAcA,cAAa;AACd,8BAAA,IAAI,YAAY,GAAG;AAAA,MAAA;AAAA,IAC3C;AAAA,EACF;AAGF,QAAM,OAAO;AAEN,SAAA,EAAE,sBAAsB,sBAAsB;AACvD;"}
|
1
|
+
{"version":3,"file":"buildTypesTask.mjs","sources":["../../../../../../src/tasks/buildTypesTask/buildTypesTask.ts"],"sourcesContent":["import { callTypescript } from \"./callTypescript.js\";\nimport { reverseMap } from \"../utils.js\";\nimport { okLog } from \"../../log.js\";\nimport type { DetectedModules } from \"../../detectModules.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesTaskOption = {\n entrypoints: Map<string, string>;\n dirs: Dirs;\n modules: DetectedModules;\n packageJson: PackageJson;\n};\n\nexport async function buildTypesTask({\n entrypoints,\n dirs,\n packageJson,\n modules,\n}: BuildTypesTaskOption) {\n const { outDir } = dirs;\n const tsEntrypoints = [...entrypoints.values()].filter((entry) =>\n entry.endsWith(\".ts\"),\n );\n const reversedEntrypoints = reverseMap(entrypoints);\n\n const entrypointToEsDtsMap = new Map<string, string>();\n const entrypointToCjsDtsMap = new Map<string, string>();\n if (tsEntrypoints.length > 0 && modules.ts == null) {\n throw new Error(\n 'smartbundle found the .ts entrypoint but required \"typescript\" to build .d.ts files. Please install the \"typescript\" dependency.',\n );\n }\n if (tsEntrypoints.length === 0 || modules.ts == null) {\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n }\n\n const dtsMap = await callTypescript({\n ts: modules.ts,\n dirs,\n packageJson,\n tsEntrypoints,\n outDir,\n });\n\n for (const [source, dts] of dtsMap.sourceToEsmDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToEsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n for (const [source, dts] of dtsMap.sourceToCjsDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToCjsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n okLog(\".d.ts\");\n\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n}\n"],"names":["entrypoints"],"mappings":";;;;;;;AAcA,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACjB,QAAA,EAAE,WAAW;AACnB,QAAM,gBAAgB,CAAC,GAAG,YAAY,OAAA,CAAQ,EAAE;AAAA,IAAO,CAAC,UACtD,MAAM,SAAS,KAAK;AAAA,EACtB;AACM,QAAA,sBAAsB,WAAW,WAAW;AAE5C,QAAA,2CAA2B,IAAoB;AAC/C,QAAA,4CAA4B,IAAoB;AACtD,MAAI,cAAc,SAAS,KAAK,QAAQ,MAAM,MAAM;AAClD,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EAAA;AAEF,MAAI,cAAc,WAAW,KAAK,QAAQ,MAAM,MAAM;AAC7C,WAAA,EAAE,sBAAsB,sBAAsB;AAAA,EAAA;AAGjD,QAAA,SAAS,MAAM,eAAe;AAAA,IAClC,IAAI,QAAQ;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAED,aAAW,CAAC,QAAQ,GAAG,KAAK,OAAO,mBAAmB;AAC9CA,UAAAA,eAAc,oBAAoB,IAAI,MAAM;AAClD,QAAIA,cAAa;AACf,iBAAW,cAAcA,cAAa;AACf,6BAAA,IAAI,YAAY,GAAG;AAAA,MAAA;AAAA,IAC1C;AAAA,EACF;AAGF,aAAW,CAAC,QAAQ,GAAG,KAAK,OAAO,mBAAmB;AAC9CA,UAAAA,eAAc,oBAAoB,IAAI,MAAM;AAClD,QAAIA,cAAa;AACf,iBAAW,cAAcA,cAAa;AACd,8BAAA,IAAI,YAAY,GAAG;AAAA,MAAA;AAAA,IAC3C;AAAA,EACF;AAGF,QAAM,OAAO;AAEN,SAAA,EAAE,sBAAsB,sBAAsB;AACvD;"}
|
@@ -70,6 +70,7 @@ async function callTypescript({
|
|
70
70
|
const esmEntrypoint = sourceToEsmDtsMap.get(sourceEntrypoint);
|
71
71
|
if (esmEntrypoint) {
|
72
72
|
const localPackages = findTypingsNames(
|
73
|
+
ts,
|
73
74
|
esmEntrypoint,
|
74
75
|
esmOutDir,
|
75
76
|
".d.mts"
|
@@ -80,13 +81,19 @@ async function callTypescript({
|
|
80
81
|
}
|
81
82
|
const cjsEntrypoint = sourceToCjsDtsMap.get(sourceEntrypoint);
|
82
83
|
if (cjsEntrypoint) {
|
83
|
-
const localPackages = findTypingsNames(
|
84
|
+
const localPackages = findTypingsNames(
|
85
|
+
ts,
|
86
|
+
cjsEntrypoint,
|
87
|
+
cjsOutDir,
|
88
|
+
".d.ts"
|
89
|
+
);
|
84
90
|
for (const p of localPackages) {
|
85
91
|
packages.add(p);
|
86
92
|
}
|
87
93
|
}
|
88
94
|
}
|
89
95
|
const { missingTypings, existingTypingPackages } = findTypingsPackages(
|
96
|
+
ts,
|
90
97
|
packages,
|
91
98
|
sourceDir
|
92
99
|
);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"callTypescript.mjs","sources":["../../../../../../src/tasks/buildTypesTask/callTypescript.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as fs from \"node:fs\";\nimport {\n inlineExtensionsMjs,\n inlineExtensionsCjs,\n} from \"./inlineExtensions.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { getMinVersion, type TS } from \"../../detectModules.js\";\nimport { BuildError } from \"../../error.js\";\nimport { findTypingsPackages } from \"./findTypingsPackages.js\";\nimport { findTypingsNames } from \"./findTypingsNames.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesOptions = {\n ts: TS;\n dirs: Dirs;\n packageJson: PackageJson;\n tsEntrypoints: string[];\n outDir: string;\n};\n\nfunction makeFileExists(outDir: string, filePath: string) {\n return (p: string) => {\n const dir = path.join(outDir, path.dirname(filePath));\n return fs.existsSync(path.join(dir, p));\n };\n}\n\nexport async function callTypescript({\n ts,\n dirs,\n tsEntrypoints,\n packageJson,\n}: BuildTypesOptions) {\n const { sourceDir, outDir, esmOutDir, cjsOutDir } = dirs;\n\n // <build d.ts>\n const sourceToCjsDtsMap = new Map<string, string>();\n const sourceToEsmDtsMap = new Map<string, string>();\n const program = ts.ts.createProgram(\n tsEntrypoints,\n ts.parsedConfig.options,\n ts.host,\n );\n program.emit(undefined, (fileName, data) => {\n // .d.ts for cjs because \"type\": \"commonjs\" in package.json\n // .d.mts for esm\n const relativePath = path.relative(sourceDir, fileName);\n const sourceFileName = fileName.replace(/\\.d\\.ts$/, \".ts\"); // Assuming source files have .ts extension\n\n const finalEsmPath = path.join(esmOutDir, relativePath);\n const esmFinalPath = finalEsmPath.replace(/\\.d\\.ts$/, \".d.mts\");\n sourceToEsmDtsMap.set(sourceFileName, esmFinalPath);\n fs.mkdirSync(path.dirname(esmFinalPath), { recursive: true });\n fs.writeFileSync(esmFinalPath, data);\n\n const finalCjsPath = path.join(cjsOutDir, relativePath);\n fs.mkdirSync(path.dirname(finalCjsPath), { recursive: true });\n const cjsFinalPath = finalCjsPath;\n fs.writeFileSync(cjsFinalPath, data);\n sourceToCjsDtsMap.set(sourceFileName, cjsFinalPath);\n });\n // </build d.ts>\n\n // <fix vscode typings>\n for (const file of [\n ...sourceToCjsDtsMap.values(),\n ...sourceToEsmDtsMap.values(),\n ]) {\n const content = fs.readFileSync(file, \"utf-8\");\n const relativePath = path.relative(outDir, file);\n if (file.endsWith(\".d.ts\")) {\n const transformedCode = inlineExtensionsCjs(\n ts.ts,\n content,\n makeFileExists(outDir, relativePath),\n );\n fs.writeFileSync(file, transformedCode);\n }\n if (file.endsWith(\".d.mts\")) {\n const transformedCode = inlineExtensionsMjs(\n ts.ts,\n content,\n makeFileExists(outDir, relativePath),\n );\n fs.writeFileSync(file, transformedCode);\n }\n }\n // </fix vscode typings>\n\n // <find all libraries names>\n const packages = new Set<string>();\n for (const sourceEntrypoint of tsEntrypoints) {\n const esmEntrypoint = sourceToEsmDtsMap.get(sourceEntrypoint);\n if (esmEntrypoint) {\n const localPackages = findTypingsNames(\n esmEntrypoint,\n esmOutDir,\n \".d.mts\",\n );\n for (const p of localPackages) {\n packages.add(p);\n }\n }\n\n const cjsEntrypoint = sourceToCjsDtsMap.get(sourceEntrypoint);\n if (cjsEntrypoint) {\n const localPackages = findTypingsNames(cjsEntrypoint
|
1
|
+
{"version":3,"file":"callTypescript.mjs","sources":["../../../../../../src/tasks/buildTypesTask/callTypescript.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as fs from \"node:fs\";\nimport {\n inlineExtensionsMjs,\n inlineExtensionsCjs,\n} from \"./inlineExtensions.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { getMinVersion, type TS } from \"../../detectModules.js\";\nimport { BuildError } from \"../../error.js\";\nimport { findTypingsPackages } from \"./findTypingsPackages.js\";\nimport { findTypingsNames } from \"./findTypingsNames.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesOptions = {\n ts: TS;\n dirs: Dirs;\n packageJson: PackageJson;\n tsEntrypoints: string[];\n outDir: string;\n};\n\nfunction makeFileExists(outDir: string, filePath: string) {\n return (p: string) => {\n const dir = path.join(outDir, path.dirname(filePath));\n return fs.existsSync(path.join(dir, p));\n };\n}\n\nexport async function callTypescript({\n ts,\n dirs,\n tsEntrypoints,\n packageJson,\n}: BuildTypesOptions) {\n const { sourceDir, outDir, esmOutDir, cjsOutDir } = dirs;\n\n // <build d.ts>\n const sourceToCjsDtsMap = new Map<string, string>();\n const sourceToEsmDtsMap = new Map<string, string>();\n const program = ts.ts.createProgram(\n tsEntrypoints,\n ts.parsedConfig.options,\n ts.host,\n );\n program.emit(undefined, (fileName, data) => {\n // .d.ts for cjs because \"type\": \"commonjs\" in package.json\n // .d.mts for esm\n const relativePath = path.relative(sourceDir, fileName);\n const sourceFileName = fileName.replace(/\\.d\\.ts$/, \".ts\"); // Assuming source files have .ts extension\n\n const finalEsmPath = path.join(esmOutDir, relativePath);\n const esmFinalPath = finalEsmPath.replace(/\\.d\\.ts$/, \".d.mts\");\n sourceToEsmDtsMap.set(sourceFileName, esmFinalPath);\n fs.mkdirSync(path.dirname(esmFinalPath), { recursive: true });\n fs.writeFileSync(esmFinalPath, data);\n\n const finalCjsPath = path.join(cjsOutDir, relativePath);\n fs.mkdirSync(path.dirname(finalCjsPath), { recursive: true });\n const cjsFinalPath = finalCjsPath;\n fs.writeFileSync(cjsFinalPath, data);\n sourceToCjsDtsMap.set(sourceFileName, cjsFinalPath);\n });\n // </build d.ts>\n\n // <fix vscode typings>\n for (const file of [\n ...sourceToCjsDtsMap.values(),\n ...sourceToEsmDtsMap.values(),\n ]) {\n const content = fs.readFileSync(file, \"utf-8\");\n const relativePath = path.relative(outDir, file);\n if (file.endsWith(\".d.ts\")) {\n const transformedCode = inlineExtensionsCjs(\n ts.ts,\n content,\n makeFileExists(outDir, relativePath),\n );\n fs.writeFileSync(file, transformedCode);\n }\n if (file.endsWith(\".d.mts\")) {\n const transformedCode = inlineExtensionsMjs(\n ts.ts,\n content,\n makeFileExists(outDir, relativePath),\n );\n fs.writeFileSync(file, transformedCode);\n }\n }\n // </fix vscode typings>\n\n // <find all libraries names>\n const packages = new Set<string>();\n for (const sourceEntrypoint of tsEntrypoints) {\n const esmEntrypoint = sourceToEsmDtsMap.get(sourceEntrypoint);\n if (esmEntrypoint) {\n const localPackages = findTypingsNames(\n ts,\n esmEntrypoint,\n esmOutDir,\n \".d.mts\",\n );\n for (const p of localPackages) {\n packages.add(p);\n }\n }\n\n const cjsEntrypoint = sourceToCjsDtsMap.get(sourceEntrypoint);\n if (cjsEntrypoint) {\n const localPackages = findTypingsNames(\n ts,\n cjsEntrypoint,\n cjsOutDir,\n \".d.ts\",\n );\n for (const p of localPackages) {\n packages.add(p);\n }\n }\n }\n // </find all libraries names>\n\n // <check not installed typings libraries>\n const { missingTypings, existingTypingPackages } = findTypingsPackages(\n ts,\n packages,\n sourceDir,\n );\n for (const lib of existingTypingPackages) {\n if (\n getMinVersion(packageJson, lib, [\n \"optionalDependencies\",\n \"devDependencies\",\n ]) == null\n ) {\n missingTypings.add(lib);\n }\n }\n if (missingTypings.size > 0) {\n const libsList = [...missingTypings].map((x) => `\"${x}\"`).join(\", \");\n throw new BuildError(\n `The typings won't installed in bundled package: ${libsList}. Please install them into dependencies or peerDependencies.`,\n );\n }\n // </check not installed typings libraries>\n\n return {\n sourceToCjsDtsMap,\n sourceToEsmDtsMap,\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;AAqBA,SAAS,eAAe,QAAgB,UAAkB;AACxD,SAAO,CAAC,MAA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AAA,IACA;AAAA,EACF;AACF;"}
|
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
import type { TS } from "../../detectModules.js";
|
2
|
+
export declare function findTypingsNames({ ts }: TS, entrypoint: string, sourceDir: string, ext: string): Set<string>;
|
@@ -1,7 +1,6 @@
|
|
1
|
-
import * as ts from "typescript";
|
2
1
|
import { relative, join } from "node:path";
|
3
2
|
import { readdirSync, statSync } from "node:fs";
|
4
|
-
function createCompilerHostWithVirtualSource(sourceDir) {
|
3
|
+
function createCompilerHostWithVirtualSource(ts, sourceDir) {
|
5
4
|
return ts.createCompilerHost({
|
6
5
|
target: ts.ScriptTarget.ESNext,
|
7
6
|
moduleResolution: ts.ModuleResolutionKind.NodeNext,
|
@@ -25,8 +24,8 @@ function collectAllFilesInDir(sourceDir, ext) {
|
|
25
24
|
}
|
26
25
|
return ret;
|
27
26
|
}
|
28
|
-
function findTypingsNames(entrypoint, sourceDir, ext) {
|
29
|
-
const host = createCompilerHostWithVirtualSource(sourceDir);
|
27
|
+
function findTypingsNames({ ts }, entrypoint, sourceDir, ext) {
|
28
|
+
const host = createCompilerHostWithVirtualSource(ts, sourceDir);
|
30
29
|
const program = ts.createProgram({
|
31
30
|
rootNames: collectAllFilesInDir(sourceDir, ext),
|
32
31
|
options: {},
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"findTypingsNames.mjs","sources":["../../../../../../src/tasks/buildTypesTask/findTypingsNames.ts"],"sourcesContent":["import * as ts from \"typescript\";\nimport { join, relative } from \"node:path\";\nimport { readdirSync, statSync } from \"node:fs\";\n\nfunction createCompilerHostWithVirtualSource(sourceDir: string) {\n return ts.createCompilerHost({\n target: ts.ScriptTarget.ESNext,\n moduleResolution: ts.ModuleResolutionKind.NodeNext,\n baseUrl: \".\",\n sourceRoot: sourceDir,\n noEmit: true,\n emitDeclarationOnly: true,\n noEmitOnError: true,\n });\n}\n\n/*\nChatGPT told me we need to specify all files in rootNames for the program to work correctly.\n */\nfunction collectAllFilesInDir(sourceDir: string, ext: string) {\n const files = readdirSync(sourceDir);\n const ret = new Array<string>();\n for (const file of files) {\n // check if the file is a directory\n const stat = statSync(join(sourceDir, file));\n if (stat.isDirectory()) {\n ret.push(...collectAllFilesInDir(join(sourceDir, file), ext));\n } else if (file.endsWith(ext)) {\n ret.push(join(sourceDir, file));\n }\n }\n\n return ret;\n}\n\nexport function findTypingsNames(\n entrypoint: string,\n sourceDir: string,\n ext: string,\n) {\n const host = createCompilerHostWithVirtualSource(sourceDir);\n const program = ts.createProgram({\n rootNames: collectAllFilesInDir(sourceDir, ext),\n options: {},\n host,\n });\n\n const packages = new Set<string>();\n const processedFiles = new Set<string>();\n const filesQueue = [relative(sourceDir, entrypoint)];\n\n function processModuleSpecifier(moduleSpecifier: ts.StringLiteral) {\n const moduleName = moduleSpecifier.text;\n if (moduleName.startsWith(\".\")) {\n filesQueue.push(moduleName.replace(/\\.js$/, ext));\n return;\n }\n\n packages.add(moduleName);\n }\n\n while (filesQueue.length > 0) {\n const relativeCurrentFile = filesQueue.pop()!;\n const currentFile = join(sourceDir, relativeCurrentFile);\n if (processedFiles.has(currentFile)) continue;\n\n const sourceFile = program.getSourceFile(currentFile);\n if (!sourceFile) continue;\n\n function visit(node: ts.Node) {\n // import \"moduleSpecifier\";\n if (\n ts.isImportDeclaration(node) &&\n ts.isStringLiteral(node.moduleSpecifier)\n ) {\n processModuleSpecifier(node.moduleSpecifier);\n }\n\n // Generic<import(\"node\")>;\n if (\n ts.isImportTypeNode(node) &&\n ts.isLiteralTypeNode(node.argument) &&\n ts.isStringLiteral(node.argument.literal)\n ) {\n processModuleSpecifier(node.argument.literal);\n }\n\n // export * from \"moduleSpecifier\";\n if (\n ts.isExportDeclaration(node) &&\n node.moduleSpecifier &&\n ts.isStringLiteral(node.moduleSpecifier)\n ) {\n processModuleSpecifier(node.moduleSpecifier);\n }\n\n ts.forEachChild(node, visit);\n }\n\n processedFiles.add(currentFile);\n\n ts.forEachChild(sourceFile, visit);\n }\n\n return packages;\n}\n"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"findTypingsNames.mjs","sources":["../../../../../../src/tasks/buildTypesTask/findTypingsNames.ts"],"sourcesContent":["import type * as ts from \"typescript\";\nimport { join, relative } from \"node:path\";\nimport { readdirSync, statSync } from \"node:fs\";\nimport type { TS } from \"../../detectModules.js\";\n\nfunction createCompilerHostWithVirtualSource(ts: TS[\"ts\"], sourceDir: string) {\n return ts.createCompilerHost({\n target: ts.ScriptTarget.ESNext,\n moduleResolution: ts.ModuleResolutionKind.NodeNext,\n baseUrl: \".\",\n sourceRoot: sourceDir,\n noEmit: true,\n emitDeclarationOnly: true,\n noEmitOnError: true,\n });\n}\n\n/*\nChatGPT told me we need to specify all files in rootNames for the program to work correctly.\n */\nfunction collectAllFilesInDir(sourceDir: string, ext: string) {\n const files = readdirSync(sourceDir);\n const ret = new Array<string>();\n for (const file of files) {\n // check if the file is a directory\n const stat = statSync(join(sourceDir, file));\n if (stat.isDirectory()) {\n ret.push(...collectAllFilesInDir(join(sourceDir, file), ext));\n } else if (file.endsWith(ext)) {\n ret.push(join(sourceDir, file));\n }\n }\n\n return ret;\n}\n\nexport function findTypingsNames(\n { ts }: TS,\n entrypoint: string,\n sourceDir: string,\n ext: string,\n) {\n const host = createCompilerHostWithVirtualSource(ts, sourceDir);\n const program = ts.createProgram({\n rootNames: collectAllFilesInDir(sourceDir, ext),\n options: {},\n host,\n });\n\n const packages = new Set<string>();\n const processedFiles = new Set<string>();\n const filesQueue = [relative(sourceDir, entrypoint)];\n\n function processModuleSpecifier(moduleSpecifier: ts.StringLiteral) {\n const moduleName = moduleSpecifier.text;\n if (moduleName.startsWith(\".\")) {\n filesQueue.push(moduleName.replace(/\\.js$/, ext));\n return;\n }\n\n packages.add(moduleName);\n }\n\n while (filesQueue.length > 0) {\n const relativeCurrentFile = filesQueue.pop()!;\n const currentFile = join(sourceDir, relativeCurrentFile);\n if (processedFiles.has(currentFile)) continue;\n\n const sourceFile = program.getSourceFile(currentFile);\n if (!sourceFile) continue;\n\n function visit(node: ts.Node) {\n // import \"moduleSpecifier\";\n if (\n ts.isImportDeclaration(node) &&\n ts.isStringLiteral(node.moduleSpecifier)\n ) {\n processModuleSpecifier(node.moduleSpecifier);\n }\n\n // Generic<import(\"node\")>;\n if (\n ts.isImportTypeNode(node) &&\n ts.isLiteralTypeNode(node.argument) &&\n ts.isStringLiteral(node.argument.literal)\n ) {\n processModuleSpecifier(node.argument.literal);\n }\n\n // export * from \"moduleSpecifier\";\n if (\n ts.isExportDeclaration(node) &&\n node.moduleSpecifier &&\n ts.isStringLiteral(node.moduleSpecifier)\n ) {\n processModuleSpecifier(node.moduleSpecifier);\n }\n\n ts.forEachChild(node, visit);\n }\n\n processedFiles.add(currentFile);\n\n ts.forEachChild(sourceFile, visit);\n }\n\n return packages;\n}\n"],"names":[],"mappings":";;AAKA,SAAS,oCAAoC,IAAc,WAAmB;AAC5E,SAAO,GAAG,mBAAmB;AAAA,IAC3B,QAAQ,GAAG,aAAa;AAAA,IACxB,kBAAkB,GAAG,qBAAqB;AAAA,IAC1C,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,qBAAqB;AAAA,IACrB,eAAe;AAAA,EAAA,CAChB;AACH;AAKA,SAAS,qBAAqB,WAAmB,KAAa;AACtD,QAAA,QAAQ,YAAY,SAAS;AAC7B,QAAA,MAAM,IAAI,MAAc;AAC9B,aAAW,QAAQ,OAAO;AAExB,UAAM,OAAO,SAAS,KAAK,WAAW,IAAI,CAAC;AACvC,QAAA,KAAK,eAAe;AAClB,UAAA,KAAK,GAAG,qBAAqB,KAAK,WAAW,IAAI,GAAG,GAAG,CAAC;AAAA,IACnD,WAAA,KAAK,SAAS,GAAG,GAAG;AAC7B,UAAI,KAAK,KAAK,WAAW,IAAI,CAAC;AAAA,IAAA;AAAA,EAChC;AAGK,SAAA;AACT;AAEO,SAAS,iBACd,EAAE,GAAA,GACF,YACA,WACA,KACA;AACM,QAAA,OAAO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|
-
|
1
|
+
import type { TS } from "../../detectModules.js";
|
2
|
+
export declare function findTypingsPackages({ ts }: TS, packages: Set<string>, sourceDir: string): {
|
2
3
|
missingTypings: Set<string>;
|
3
4
|
existingTypingPackages: Set<string>;
|
4
5
|
};
|
@@ -1,6 +1,5 @@
|
|
1
|
-
import * as ts from "typescript";
|
2
1
|
import * as path from "node:path";
|
3
|
-
function createVirtualHostFunctions(virtualFilePath, virtualSourceContent, originalHost) {
|
2
|
+
function createVirtualHostFunctions(ts, virtualFilePath, virtualSourceContent, originalHost) {
|
4
3
|
const getSourceFile = (fileName, languageVersion) => {
|
5
4
|
if (fileName === virtualFilePath) {
|
6
5
|
return ts.createSourceFile(
|
@@ -29,7 +28,7 @@ function createVirtualHostFunctions(virtualFilePath, virtualSourceContent, origi
|
|
29
28
|
readFile
|
30
29
|
};
|
31
30
|
}
|
32
|
-
function createCompilerHostWithVirtualSource(packages, sourceDir) {
|
31
|
+
function createCompilerHostWithVirtualSource(ts, packages, sourceDir) {
|
33
32
|
const virtualSourceContent = [...packages].map((p) => `import "${p}";`).join("\n") + // for ignoring the `Generated an empty chunk: "."` error
|
34
33
|
"export const a = 1;\n";
|
35
34
|
const virtualFilePath = path.join(sourceDir, "virtual.ts");
|
@@ -46,6 +45,7 @@ function createCompilerHostWithVirtualSource(packages, sourceDir) {
|
|
46
45
|
}
|
47
46
|
});
|
48
47
|
const virtualFunctions = createVirtualHostFunctions(
|
48
|
+
ts,
|
49
49
|
virtualFilePath,
|
50
50
|
virtualSourceContent,
|
51
51
|
originalHost
|
@@ -59,8 +59,9 @@ function createCompilerHostWithVirtualSource(packages, sourceDir) {
|
|
59
59
|
virtualFilePath
|
60
60
|
};
|
61
61
|
}
|
62
|
-
function findTypingsPackages(packages, sourceDir) {
|
62
|
+
function findTypingsPackages({ ts }, packages, sourceDir) {
|
63
63
|
const { host, virtualFilePath } = createCompilerHostWithVirtualSource(
|
64
|
+
ts,
|
64
65
|
packages,
|
65
66
|
sourceDir
|
66
67
|
);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"findTypingsPackages.mjs","sources":["../../../../../../src/tasks/buildTypesTask/findTypingsPackages.ts"],"sourcesContent":["import * as ts from \"typescript\";\nimport * as path from \"node:path\";\n\ntype HostFunctions = {\n getSourceFile: ts.CompilerHost[\"getSourceFile\"];\n fileExists: ts.CompilerHost[\"fileExists\"];\n readFile: ts.CompilerHost[\"readFile\"];\n};\n\nfunction createVirtualHostFunctions(\n virtualFilePath: string,\n virtualSourceContent: string,\n originalHost: ts.CompilerHost,\n): HostFunctions {\n const getSourceFile: ts.CompilerHost[\"getSourceFile\"] = (\n fileName,\n languageVersion,\n ) => {\n if (fileName === virtualFilePath) {\n return ts.createSourceFile(\n fileName,\n virtualSourceContent,\n languageVersion,\n );\n }\n return originalHost.getSourceFile(fileName, languageVersion);\n };\n\n const fileExists: ts.CompilerHost[\"fileExists\"] = (fileName) => {\n if (fileName === virtualFilePath) {\n return true;\n }\n return originalHost.fileExists(fileName);\n };\n\n const readFile: ts.CompilerHost[\"readFile\"] = (fileName) => {\n if (fileName === virtualFilePath) {\n return virtualSourceContent;\n }\n return originalHost.readFile(fileName);\n };\n\n return {\n getSourceFile,\n fileExists,\n readFile,\n };\n}\n\nfunction createCompilerHostWithVirtualSource(\n packages: Set<string>,\n sourceDir: string,\n) {\n const virtualSourceContent =\n [...packages].map((p) => `import \"${p}\";`).join(\"\\n\") +\n // for ignoring the `Generated an empty chunk: \".\"` error\n \"export const a = 1;\\n\";\n const virtualFilePath = path.join(sourceDir, \"virtual.ts\");\n\n const originalHost = ts.createCompilerHost({\n target: ts.ScriptTarget.ESNext,\n moduleResolution: ts.ModuleResolutionKind.NodeNext,\n baseUrl: \".\",\n sourceRoot: sourceDir,\n noEmit: true,\n emitDeclarationOnly: true,\n noEmitOnError: true,\n paths: {\n \"*\": [\"node_modules/*\"],\n },\n });\n const virtualFunctions = createVirtualHostFunctions(\n virtualFilePath,\n virtualSourceContent,\n originalHost,\n );\n\n return {\n host: new Proxy(originalHost, {\n get(target, prop: keyof ts.CompilerHost) {\n return virtualFunctions[prop as keyof HostFunctions] || target[prop];\n },\n }),\n virtualFilePath,\n };\n}\n\nexport function findTypingsPackages(packages: Set<string
|
1
|
+
{"version":3,"file":"findTypingsPackages.mjs","sources":["../../../../../../src/tasks/buildTypesTask/findTypingsPackages.ts"],"sourcesContent":["import type * as ts from \"typescript\";\nimport * as path from \"node:path\";\nimport type { TS } from \"../../detectModules.js\";\n\ntype HostFunctions = {\n getSourceFile: ts.CompilerHost[\"getSourceFile\"];\n fileExists: ts.CompilerHost[\"fileExists\"];\n readFile: ts.CompilerHost[\"readFile\"];\n};\n\nfunction createVirtualHostFunctions(\n ts: TS[\"ts\"],\n virtualFilePath: string,\n virtualSourceContent: string,\n originalHost: ts.CompilerHost,\n): HostFunctions {\n const getSourceFile: ts.CompilerHost[\"getSourceFile\"] = (\n fileName,\n languageVersion,\n ) => {\n if (fileName === virtualFilePath) {\n return ts.createSourceFile(\n fileName,\n virtualSourceContent,\n languageVersion,\n );\n }\n return originalHost.getSourceFile(fileName, languageVersion);\n };\n\n const fileExists: ts.CompilerHost[\"fileExists\"] = (fileName) => {\n if (fileName === virtualFilePath) {\n return true;\n }\n return originalHost.fileExists(fileName);\n };\n\n const readFile: ts.CompilerHost[\"readFile\"] = (fileName) => {\n if (fileName === virtualFilePath) {\n return virtualSourceContent;\n }\n return originalHost.readFile(fileName);\n };\n\n return {\n getSourceFile,\n fileExists,\n readFile,\n };\n}\n\nfunction createCompilerHostWithVirtualSource(\n ts: TS[\"ts\"],\n packages: Set<string>,\n sourceDir: string,\n) {\n const virtualSourceContent =\n [...packages].map((p) => `import \"${p}\";`).join(\"\\n\") +\n // for ignoring the `Generated an empty chunk: \".\"` error\n \"export const a = 1;\\n\";\n const virtualFilePath = path.join(sourceDir, \"virtual.ts\");\n\n const originalHost = ts.createCompilerHost({\n target: ts.ScriptTarget.ESNext,\n moduleResolution: ts.ModuleResolutionKind.NodeNext,\n baseUrl: \".\",\n sourceRoot: sourceDir,\n noEmit: true,\n emitDeclarationOnly: true,\n noEmitOnError: true,\n paths: {\n \"*\": [\"node_modules/*\"],\n },\n });\n const virtualFunctions = createVirtualHostFunctions(\n ts,\n virtualFilePath,\n virtualSourceContent,\n originalHost,\n );\n\n return {\n host: new Proxy(originalHost, {\n get(target, prop: keyof ts.CompilerHost) {\n return virtualFunctions[prop as keyof HostFunctions] || target[prop];\n },\n }),\n virtualFilePath,\n };\n}\n\nexport function findTypingsPackages(\n { ts }: TS,\n packages: Set<string>,\n sourceDir: string,\n) {\n const { host, virtualFilePath } = createCompilerHostWithVirtualSource(\n ts,\n packages,\n sourceDir,\n );\n\n const program = ts.createProgram({\n rootNames: [virtualFilePath],\n options: {},\n host: host,\n });\n\n const sourceFile = program.getSourceFile(virtualFilePath);\n if (!sourceFile) {\n throw new Error(\n \"[getSourceFile] Impossible error inside findMissingTypings\",\n );\n }\n\n const missingTypings = new Set<string>();\n const existingTypingPackages = new Set<string>();\n sourceFile.forEachChild((node) => {\n if (ts.isImportDeclaration(node)) {\n const moduleSpecifier = node.moduleSpecifier;\n if (ts.isStringLiteral(moduleSpecifier)) {\n const moduleResolution = ts.resolveModuleName(\n moduleSpecifier.text,\n virtualFilePath,\n {},\n host,\n );\n\n if (!moduleResolution?.resolvedModule?.packageId) {\n missingTypings.add(moduleSpecifier.text);\n } else {\n existingTypingPackages.add(\n moduleResolution.resolvedModule.packageId.name,\n );\n }\n }\n }\n });\n\n return { missingTypings, existingTypingPackages };\n}\n"],"names":[],"mappings":";AAUA,SAAS,2BACP,IACA,iBACA,sBACA,cACe;AACT,QAAA,gBAAkD,CACtD,UACA,oBACG;AACH,QAAI,aAAa,iBAAiB;AAChC,aAAO,GAAG;AAAA,QACR;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IAAA;AAEK,WAAA,aAAa,cAAc,UAAU,eAAe;AAAA,EAC7D;AAEM,QAAA,aAA4C,CAAC,aAAa;AAC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AAA,aAAa,QAAQ,cAAc,eAAe;AACxD,MAAI,CAAC,YAAY;AACf,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EAAA;AAGI,QAAA,qCAAqB,IAAY;AACjC,QAAA,6CAA6B,IAAY;AACpC,aAAA,aAAa,CAAC,SAAS;;AAC5B,QAAA,GAAG,oBAAoB,IAAI,GAAG;AAChC,YAAM,kBAAkB,KAAK;AACzB,UAAA,GAAG,gBAAgB,eAAe,GAAG;AACvC,cAAM,mBAAmB,GAAG;AAAA,UAC1B,gBAAgB;AAAA,UAChB;AAAA,UACA,CAAC;AAAA,UACD;AAAA,QACF;AAEI,YAAA,GAAC,0DAAkB,mBAAlB,mBAAkC,YAAW;AACjC,yBAAA,IAAI,gBAAgB,IAAI;AAAA,QAAA,OAClC;AACkB,iCAAA;AAAA,YACrB,iBAAiB,eAAe,UAAU;AAAA,UAC5C;AAAA,QAAA;AAAA,MACF;AAAA,IACF;AAAA,EACF,CACD;AAEM,SAAA,EAAE,gBAAgB,uBAAuB;AAClD;"}
|
@@ -1,16 +1,6 @@
|
|
1
|
-
import { type UserConfig
|
1
|
+
import { type UserConfig } from "vite";
|
2
2
|
type ViteTaskParams = {
|
3
3
|
viteConfig: UserConfig;
|
4
4
|
};
|
5
|
-
type BuildSuccess = {
|
6
|
-
error: false;
|
7
|
-
output: Rollup.OutputChunk[];
|
8
|
-
};
|
9
|
-
type BuildErrorType = {
|
10
|
-
error: true;
|
11
|
-
errors: Array<string>;
|
12
|
-
};
|
13
|
-
type BuildResult = BuildSuccess | BuildErrorType;
|
14
|
-
export declare function buildVite({ viteConfig, }: ViteTaskParams): Promise<BuildResult>;
|
15
5
|
export declare function viteTask({ viteConfig }: ViteTaskParams): Promise<any>;
|
16
6
|
export {};
|
@@ -2,9 +2,8 @@ import { build } from "vite";
|
|
2
2
|
import { errors } from "../errors.mjs";
|
3
3
|
import { okLog } from "../log.mjs";
|
4
4
|
import { BuildError } from "../error.mjs";
|
5
|
-
|
6
|
-
|
7
|
-
}) {
|
5
|
+
import { PrettyError } from "../PrettyErrors.mjs";
|
6
|
+
async function buildVite({ viteConfig }) {
|
8
7
|
try {
|
9
8
|
const outputs = await build(viteConfig);
|
10
9
|
if (!Array.isArray(outputs)) {
|
@@ -20,6 +19,12 @@ async function buildVite({
|
|
20
19
|
)
|
21
20
|
};
|
22
21
|
} catch (e) {
|
22
|
+
if (e instanceof PrettyError) {
|
23
|
+
return {
|
24
|
+
error: true,
|
25
|
+
errors: [e]
|
26
|
+
};
|
27
|
+
}
|
23
28
|
if (e instanceof Error) {
|
24
29
|
return {
|
25
30
|
error: true,
|
@@ -35,13 +40,14 @@ async function buildVite({
|
|
35
40
|
async function viteTask({ viteConfig }) {
|
36
41
|
const outputs = await buildVite({ viteConfig });
|
37
42
|
if (outputs.error) {
|
38
|
-
throw outputs.errors.map(
|
43
|
+
throw outputs.errors.map(
|
44
|
+
(e) => e instanceof PrettyError ? e : new BuildError(e)
|
45
|
+
);
|
39
46
|
}
|
40
47
|
okLog("Vite");
|
41
48
|
return outputs.output;
|
42
49
|
}
|
43
50
|
export {
|
44
|
-
buildVite,
|
45
51
|
viteTask
|
46
52
|
};
|
47
53
|
//# sourceMappingURL=viteTask.mjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"viteTask.mjs","sources":["../../../../../src/tasks/viteTask.ts"],"sourcesContent":["import { build, type UserConfig, type Rollup } from \"vite\";\nimport { errors } from \"../errors.js\";\nimport { okLog } from \"../log.js\";\nimport { BuildError } from \"../error.js\";\n\ntype ViteTaskParams = {\n viteConfig: UserConfig;\n};\n\ntype BuildSuccess = {\n error: false;\n output: Rollup.OutputChunk[];\n};\ntype BuildErrorType = {\n error: true;\n errors: Array<string>;\n};\n\ntype BuildResult = BuildSuccess | BuildErrorType;\n\
|
1
|
+
{"version":3,"file":"viteTask.mjs","sources":["../../../../../src/tasks/viteTask.ts"],"sourcesContent":["import { build, type UserConfig, type Rollup } from \"vite\";\nimport { errors } from \"../errors.js\";\nimport { okLog } from \"../log.js\";\nimport { BuildError } from \"../error.js\";\nimport { PrettyError } from \"../PrettyErrors.js\";\n\ntype ViteTaskParams = {\n viteConfig: UserConfig;\n};\n\ntype BuildSuccess = {\n error: false;\n output: Rollup.OutputChunk[];\n};\ntype BuildErrorType = {\n error: true;\n errors: Array<string | PrettyError>;\n};\n\ntype BuildResult = BuildSuccess | BuildErrorType;\n\nasync function buildVite({ viteConfig }: ViteTaskParams): Promise<BuildResult> {\n try {\n const outputs = await build(viteConfig);\n if (!Array.isArray(outputs)) {\n return {\n error: true,\n errors: [errors.rollupError],\n };\n }\n\n return {\n error: false,\n output: outputs.flatMap((x) =>\n x.output.filter((x) => x.type === \"chunk\"),\n ),\n };\n } catch (e) {\n if (e instanceof PrettyError) {\n return {\n error: true,\n errors: [e],\n };\n }\n if (e instanceof Error) {\n return {\n error: true,\n errors: [e.message],\n };\n }\n }\n return {\n error: true,\n errors: [errors.rollupError],\n };\n}\n\nexport async function viteTask({ viteConfig }: ViteTaskParams) {\n const outputs = await buildVite({ viteConfig });\n if (outputs.error) {\n throw outputs.errors.map((e) =>\n e instanceof PrettyError ? e : new BuildError(e),\n );\n }\n\n okLog(\"Vite\");\n return outputs.output;\n}\n"],"names":["x"],"mappings":";;;;;AAqBA,eAAe,UAAU,EAAE,cAAoD;AACzE,MAAA;AACI,UAAA,UAAU,MAAM,MAAM,UAAU;AACtC,QAAI,CAAC,MAAM,QAAQ,OAAO,GAAG;AACpB,aAAA;AAAA,QACL,OAAO;AAAA,QACP,QAAQ,CAAC,OAAO,WAAW;AAAA,MAC7B;AAAA,IAAA;AAGK,WAAA;AAAA,MACL,OAAO;AAAA,MACP,QAAQ,QAAQ;AAAA,QAAQ,CAAC,MACvB,EAAE,OAAO,OAAO,CAACA,OAAMA,GAAE,SAAS,OAAO;AAAA,MAAA;AAAA,IAE7C;AAAA,WACO,GAAG;AACV,QAAI,aAAa,aAAa;AACrB,aAAA;AAAA,QACL,OAAO;AAAA,QACP,QAAQ,CAAC,CAAC;AAAA,MACZ;AAAA,IAAA;AAEF,QAAI,aAAa,OAAO;AACf,aAAA;AAAA,QACL,OAAO;AAAA,QACP,QAAQ,CAAC,EAAE,OAAO;AAAA,MACpB;AAAA,IAAA;AAAA,EACF;AAEK,SAAA;AAAA,IACL,OAAO;AAAA,IACP,QAAQ,CAAC,OAAO,WAAW;AAAA,EAC7B;AACF;AAEsB,eAAA,SAAS,EAAE,cAA8B;AAC7D,QAAM,UAAU,MAAM,UAAU,EAAE,YAAY;AAC9C,MAAI,QAAQ,OAAO;AACjB,UAAM,QAAQ,OAAO;AAAA,MAAI,CAAC,MACxB,aAAa,cAAc,IAAI,IAAI,WAAW,CAAC;AAAA,IACjD;AAAA,EAAA;AAGF,QAAM,MAAM;AACZ,SAAO,QAAQ;AACjB;"}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "smartbundle",
|
3
3
|
"type": "commonjs",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.13.0-alpha.1",
|
5
5
|
"bin": {
|
6
6
|
"smartbundle": "__bin__/smartbundle.js"
|
7
7
|
},
|
@@ -28,6 +28,7 @@
|
|
28
28
|
"semver": "^7.6.3",
|
29
29
|
"vite": "^5.4.11",
|
30
30
|
"yargs": "^17.7.2",
|
31
|
+
"youch": "4.1.0-beta.4",
|
31
32
|
"zod": "^3.24.0"
|
32
33
|
},
|
33
34
|
"repository": {
|