smartbundle 0.12.4 → 0.13.0-alpha.0
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/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/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/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/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
|
@@ -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;"}
|
|
@@ -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":"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"}
|
|
@@ -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,oCAAoC,IAAI,SAAS;AACxD,QAAA,UAAU,GAAG,cAAc;AAAA,IAC/B,WAAW,qBAAqB,WAAW,GAAG;AAAA,IAC9C,SAAS,CAAC;AAAA,IACV;AAAA,EAAA,CACD;AAEK,QAAA,+BAAe,IAAY;AAC3B,QAAA,qCAAqB,IAAY;AACvC,QAAM,aAAa,CAAC,SAAS,WAAW,UAAU,CAAC;AAEnD,WAAS,uBAAuB,iBAAmC;AACjE,UAAM,aAAa,gBAAgB;AAC/B,QAAA,WAAW,WAAW,GAAG,GAAG;AAC9B,iBAAW,KAAK,WAAW,QAAQ,SAAS,GAAG,CAAC;AAChD;AAAA,IAAA;AAGF,aAAS,IAAI,UAAU;AAAA,EAAA;AAGlB,SAAA,WAAW,SAAS,GAAG;AAQnB,QAAA,QAAT,SAAe,MAAe;AAG1B,UAAA,GAAG,oBAAoB,IAAI,KAC3B,GAAG,gBAAgB,KAAK,eAAe,GACvC;AACA,+BAAuB,KAAK,eAAe;AAAA,MAAA;AAI7C,UACE,GAAG,iBAAiB,IAAI,KACxB,GAAG,kBAAkB,KAAK,QAAQ,KAClC,GAAG,gBAAgB,KAAK,SAAS,OAAO,GACxC;AACuB,+BAAA,KAAK,SAAS,OAAO;AAAA,MAAA;AAK5C,UAAA,GAAG,oBAAoB,IAAI,KAC3B,KAAK,mBACL,GAAG,gBAAgB,KAAK,eAAe,GACvC;AACA,+BAAuB,KAAK,eAAe;AAAA,MAAA;AAG1C,SAAA,aAAa,MAAM,KAAK;AAAA,IAC7B;AAnCM,UAAA,sBAAsB,WAAW,IAAI;AACrC,UAAA,cAAc,KAAK,WAAW,mBAAmB;AACnD,QAAA,eAAe,IAAI,WAAW,EAAG;AAE/B,UAAA,aAAa,QAAQ,cAAc,WAAW;AACpD,QAAI,CAAC,WAAY;AAgCjB,mBAAe,IAAI,WAAW;AAE3B,OAAA,aAAa,YAAY,KAAK;AAAA,EAAA;AAG5B,SAAA;AACT;"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
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;AAC9D,QAAI,aAAa,iBAAiB;AACzB,aAAA;AAAA,IAAA;AAEF,WAAA,aAAa,WAAW,QAAQ;AAAA,EACzC;AAEM,QAAA,WAAwC,CAAC,aAAa;AAC1D,QAAI,aAAa,iBAAiB;AACzB,aAAA;AAAA,IAAA;AAEF,WAAA,aAAa,SAAS,QAAQ;AAAA,EACvC;AAEO,SAAA;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,SAAS,oCACP,IACA,UACA,WACA;AACA,QAAM,uBACJ,CAAC,GAAG,QAAQ,EAAE,IAAI,CAAC,MAAM,WAAW,CAAC,IAAI,EAAE,KAAK,IAAI;AAAA,EAEpD;AACF,QAAM,kBAAkB,KAAK,KAAK,WAAW,YAAY;AAEnD,QAAA,eAAe,GAAG,mBAAmB;AAAA,IACzC,QAAQ,GAAG,aAAa;AAAA,IACxB,kBAAkB,GAAG,qBAAqB;AAAA,IAC1C,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,qBAAqB;AAAA,IACrB,eAAe;AAAA,IACf,OAAO;AAAA,MACL,KAAK,CAAC,gBAAgB;AAAA,IAAA;AAAA,EACxB,CACD;AACD,QAAM,mBAAmB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEO,SAAA;AAAA,IACL,MAAM,IAAI,MAAM,cAAc;AAAA,MAC5B,IAAI,QAAQ,MAA6B;AACvC,eAAO,iBAAiB,IAA2B,KAAK,OAAO,IAAI;AAAA,MAAA;AAAA,IACrE,CACD;AAAA,IACD;AAAA,EACF;AACF;AAEO,SAAS,oBACd,EAAE,MACF,UACA,WACA;AACM,QAAA,EAAE,MAAM,gBAAA,IAAoB;AAAA,IAChC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEM,QAAA,UAAU,GAAG,cAAc;AAAA,IAC/B,WAAW,CAAC,eAAe;AAAA,IAC3B,SAAS,CAAC;AAAA,IACV;AAAA,EAAA,CACD;AAEK,QAAA,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.0",
|
|
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": {
|