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
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"PrettyErrors.js","sources":["../../../../src/PrettyErrors.ts"],"sourcesContent":["export class PrettyError extends Error {}\n"],"names":[],"mappings":";;AAAO,MAAM,oBAAoB,MAAM;AAAC;;"}
|
@@ -5,8 +5,9 @@ type CreateViteConfigParam = {
|
|
5
5
|
dirs: Dirs;
|
6
6
|
packageJson: PackageJson;
|
7
7
|
modules: DetectedModules;
|
8
|
+
test?: boolean;
|
8
9
|
};
|
9
|
-
export declare function createViteConfig({ dirs, packageJson, modules, }: CreateViteConfigParam): {
|
10
|
+
export declare function createViteConfig({ dirs, packageJson, modules, test, }: CreateViteConfigParam): {
|
10
11
|
viteConfig: import("vite").UserConfig;
|
11
12
|
entrypoints: Map<string, string>;
|
12
13
|
bins: Map<string, string>;
|
@@ -5,9 +5,10 @@ require("./args.js");
|
|
5
5
|
require("node:fs/promises");
|
6
6
|
require("zod");
|
7
7
|
const vite = require("vite");
|
8
|
-
const index$
|
9
|
-
const index = require("./plugins/react/index.js");
|
8
|
+
const index$2 = require("./plugins/babel/index.js");
|
9
|
+
const index$1 = require("./plugins/react/index.js");
|
10
10
|
require("semver");
|
11
|
+
const index = require("./plugins/imports/index.js");
|
11
12
|
function mapToObject(map) {
|
12
13
|
const obj = {};
|
13
14
|
for (const [key, value] of map) {
|
@@ -15,38 +16,11 @@ function mapToObject(map) {
|
|
15
16
|
}
|
16
17
|
return obj;
|
17
18
|
}
|
18
|
-
function createExternalDepValidator(packageJson) {
|
19
|
-
const allExternalPackages = /* @__PURE__ */ new Set();
|
20
|
-
for (const key of [
|
21
|
-
"dependencies",
|
22
|
-
"optionalDependencies",
|
23
|
-
"peerDependencies"
|
24
|
-
]) {
|
25
|
-
for (const dep of Object.keys(packageJson[key] ?? {})) {
|
26
|
-
allExternalPackages.add(dep);
|
27
|
-
}
|
28
|
-
}
|
29
|
-
allExternalPackages.add(packageJson.name);
|
30
|
-
return (id) => {
|
31
|
-
if (id.startsWith("node:")) {
|
32
|
-
return true;
|
33
|
-
}
|
34
|
-
const segments = id.split("/");
|
35
|
-
let current = "";
|
36
|
-
for (const segment of segments) {
|
37
|
-
current += segment;
|
38
|
-
if (allExternalPackages.has(current)) {
|
39
|
-
return true;
|
40
|
-
}
|
41
|
-
current += "/";
|
42
|
-
}
|
43
|
-
return false;
|
44
|
-
};
|
45
|
-
}
|
46
19
|
function createViteConfig({
|
47
20
|
dirs,
|
48
21
|
packageJson,
|
49
|
-
modules
|
22
|
+
modules,
|
23
|
+
test
|
50
24
|
}) {
|
51
25
|
const { sourceDir, outDir, esmOutDir, cjsOutDir } = dirs;
|
52
26
|
const entrypoints = /* @__PURE__ */ new Map();
|
@@ -63,13 +37,13 @@ function createViteConfig({
|
|
63
37
|
}
|
64
38
|
}
|
65
39
|
const mergedEntries = new Map([...entrypoints, ...bins]);
|
66
|
-
const depsValidator = createExternalDepValidator(packageJson);
|
67
40
|
const esmRelativeOutPath = path.relative(outDir, esmOutDir);
|
68
41
|
const cjsRelativeOutPath = path.relative(outDir, cjsOutDir);
|
69
42
|
const viteConfig = vite.defineConfig({
|
70
43
|
plugins: [
|
71
|
-
index.
|
72
|
-
index$1.
|
44
|
+
index.importsPlugin(packageJson, test),
|
45
|
+
index$1.reactPlugin({ modules }),
|
46
|
+
index$2.babelPlugin({ packageJson, dirs, modules })
|
73
47
|
],
|
74
48
|
publicDir: false,
|
75
49
|
root: sourceDir,
|
@@ -112,7 +86,6 @@ function createViteConfig({
|
|
112
86
|
}
|
113
87
|
},
|
114
88
|
rollupOptions: {
|
115
|
-
external: depsValidator,
|
116
89
|
output: {
|
117
90
|
preserveModulesRoot: sourceDir,
|
118
91
|
exports: "named",
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"createViteConfig.js","sources":["../../../../src/createViteConfig.ts"],"sourcesContent":["import { type Dirs } from \"./resolveDirs.js\";\nimport { type PackageJson } from \"./packageJson.js\";\nimport { join, relative } from \"node:path\";\nimport { defineConfig } from \"vite\";\nimport { babelPlugin } from \"./plugins/babel/index.js\";\nimport { reactPlugin } from \"./plugins/react/index.js\";\nimport { type DetectedModules } from \"./detectModules.js\";\n\ntype CreateViteConfigParam = {\n dirs: Dirs;\n packageJson: PackageJson;\n modules: DetectedModules;\n};\n\nfunction mapToObject(map: Map<string, string>) {\n const obj: Record<string, string> = {};\n for (const [key, value] of map) {\n obj[key] = value;\n }\n return obj;\n}\n\
|
1
|
+
{"version":3,"file":"createViteConfig.js","sources":["../../../../src/createViteConfig.ts"],"sourcesContent":["import { type Dirs } from \"./resolveDirs.js\";\nimport { type PackageJson } from \"./packageJson.js\";\nimport { join, relative } from \"node:path\";\nimport { defineConfig } from \"vite\";\nimport { babelPlugin } from \"./plugins/babel/index.js\";\nimport { reactPlugin } from \"./plugins/react/index.js\";\nimport { type DetectedModules } from \"./detectModules.js\";\nimport { importsPlugin } from \"./plugins/imports/index.js\";\n\ntype CreateViteConfigParam = {\n dirs: Dirs;\n packageJson: PackageJson;\n modules: DetectedModules;\n test?: boolean;\n};\n\nfunction mapToObject(map: Map<string, string>) {\n const obj: Record<string, string> = {};\n for (const [key, value] of map) {\n obj[key] = value;\n }\n return obj;\n}\n\nexport function createViteConfig({\n dirs,\n packageJson,\n modules,\n test,\n}: CreateViteConfigParam) {\n const { sourceDir, outDir, esmOutDir, cjsOutDir } = dirs;\n\n const entrypoints = new Map<string, string>();\n if (packageJson.exports) {\n for (const [key, value] of packageJson.exports) {\n const entry = join(sourceDir, value);\n entrypoints.set(key, entry);\n }\n }\n\n const bins = new Map<string, string>();\n if (packageJson.bin) {\n for (const [key, value] of packageJson.bin) {\n bins.set(key, join(sourceDir, value));\n }\n }\n\n const mergedEntries = new Map([...entrypoints, ...bins]);\n\n const esmRelativeOutPath = relative(outDir, esmOutDir);\n const cjsRelativeOutPath = relative(outDir, cjsOutDir);\n const viteConfig = defineConfig({\n plugins: [\n importsPlugin(packageJson, test),\n reactPlugin({ modules }),\n babelPlugin({ packageJson, dirs, modules }),\n ],\n publicDir: false,\n root: sourceDir,\n logLevel: \"silent\",\n build: {\n outDir,\n write: true,\n minify: false,\n emptyOutDir: false,\n sourcemap: true,\n assetsInlineLimit: 0,\n terserOptions: {\n compress: false,\n mangle: false,\n },\n lib: {\n entry: mapToObject(mergedEntries),\n formats: [\"es\", \"cjs\"],\n fileName: (format, entryName) => {\n const entrypoint = mergedEntries.get(entryName);\n if (!entrypoint) {\n const noExt = entryName.replace(/\\.[^.]+$/, \"\");\n if (format === \"es\") {\n return join(esmRelativeOutPath, `${noExt}.mjs`);\n } else {\n return join(cjsRelativeOutPath, `${noExt}.js`);\n }\n }\n\n if (format === \"es\") {\n return join(\n esmRelativeOutPath,\n relative(sourceDir, entrypoint).replace(/\\.[^.]+$/, \"\") + \".mjs\",\n );\n } else {\n return join(\n cjsRelativeOutPath,\n relative(sourceDir, entrypoint).replace(/\\.[^.]+$/, \"\") + \".js\",\n );\n }\n },\n },\n rollupOptions: {\n output: {\n preserveModulesRoot: sourceDir,\n exports: \"named\",\n preserveModules: true,\n },\n },\n },\n });\n\n return { viteConfig, entrypoints, bins };\n}\n"],"names":["join","relative","defineConfig","importsPlugin","reactPlugin","babelPlugin"],"mappings":";;;;;;;;;;;AAgBA,SAAS,YAAY,KAA0B;AAC7C,QAAM,MAA8B,CAAC;AACrC,aAAW,CAAC,KAAK,KAAK,KAAK,KAAK;AAC9B,QAAI,GAAG,IAAI;AAAA,EAAA;AAEN,SAAA;AACT;AAEO,S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a,cAAc,IAAI,SAAS;AAC9C,cAAI,CAAC,YAAY;AACf,kBAAM,QAAQ,UAAU,QAAQ,YAAY,EAAE;AAC9C,gBAAI,WAAW,MAAM;AACnB,qBAAOL,KAAK,KAAA,oBAAoB,GAAG,KAAK,MAAM;AAAA,YAAA,OACzC;AACL,qBAAOA,KAAK,KAAA,oBAAoB,GAAG,KAAK,KAAK;AAAA,YAAA;AAAA,UAC/C;AAGF,cAAI,WAAW,MAAM;AACZ,mBAAAA,KAAA;AAAA,cACL;AAAA,cACAC,cAAS,WAAW,UAAU,EAAE,QAAQ,YAAY,EAAE,IAAI;AAAA,YAC5D;AAAA,UAAA,OACK;AACE,mBAAAD,KAAA;AAAA,cACL;AAAA,cACAC,cAAS,WAAW,UAAU,EAAE,QAAQ,YAAY,EAAE,IAAI;AAAA,YAC5D;AAAA,UAAA;AAAA,QACF;AAAA,MAEJ;AAAA,MACA,eAAe;AAAA,QACb,QAAQ;AAAA,UACN,qBAAqB;AAAA,UACrB,SAAS;AAAA,UACT,iBAAiB;AAAA,QAAA;AAAA,MACnB;AAAA,IACF;AAAA,EACF,CACD;AAEM,SAAA,EAAE,YAAY,aAAa,KAAK;AACzC;;"}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { type Args } from "./args.js";
|
2
|
+
import { PrettyError } from "./PrettyErrors.js";
|
2
3
|
export declare function defineViteConfig(args?: Args): Promise<import("vite").UserConfig | {
|
3
4
|
error: boolean;
|
4
5
|
errors: string[];
|
@@ -7,7 +8,7 @@ type RunResult = {
|
|
7
8
|
error: false;
|
8
9
|
} | {
|
9
10
|
error: true;
|
10
|
-
errors: Array<string>;
|
11
|
+
errors: Array<string | PrettyError>;
|
11
12
|
};
|
12
13
|
export declare function run(args: Args): Promise<RunResult>;
|
13
14
|
export {};
|
@@ -17,6 +17,7 @@ const pipeline = require("./pipeline.js");
|
|
17
17
|
require("./args.js");
|
18
18
|
const viteTask = require("./tasks/viteTask.js");
|
19
19
|
const promiseSettledResultErrors = require("./promiseSettledResultErrors.js");
|
20
|
+
const PrettyErrors = require("./PrettyErrors.js");
|
20
21
|
function setExports(exportsMap, exportName, mapFn) {
|
21
22
|
const entry = exportsMap.get(exportName) ?? {};
|
22
23
|
exportsMap.set(exportName, mapFn(entry));
|
@@ -37,7 +38,12 @@ async function defineViteConfig(args = {}) {
|
|
37
38
|
return { error: true, errors: modulesResult.errors };
|
38
39
|
}
|
39
40
|
const { modules } = modulesResult;
|
40
|
-
const { viteConfig } = createViteConfig.createViteConfig({
|
41
|
+
const { viteConfig } = createViteConfig.createViteConfig({
|
42
|
+
dirs,
|
43
|
+
packageJson: packageJson$1,
|
44
|
+
modules,
|
45
|
+
test: true
|
46
|
+
});
|
41
47
|
return viteConfig;
|
42
48
|
}
|
43
49
|
async function run(args) {
|
@@ -110,6 +116,9 @@ async function run(args) {
|
|
110
116
|
)
|
111
117
|
]);
|
112
118
|
const errors = promiseSettledResultErrors.promiseSettledResultErrors(tasksRes).map((res) => {
|
119
|
+
if (res instanceof PrettyErrors.PrettyError) {
|
120
|
+
return res;
|
121
|
+
}
|
113
122
|
if (res instanceof error.BuildError) {
|
114
123
|
return res.error;
|
115
124
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/index.ts"],"sourcesContent":["import { relative } from \"node:path\";\nimport { mkdir, rm } from \"node:fs/promises\";\nimport { parsePackageJson } from \"./packageJson.js\";\nimport { type ExportsObject, writePackageJson } from \"./writePackageJson.js\";\nimport { resolveDirs } from \"./resolveDirs.js\";\nimport { createViteConfig } from \"./createViteConfig.js\";\nimport { copyStaticFilesTask } from \"./tasks/copyStaticFilesTask.js\";\nimport { buildTypesTask } from \"./tasks/buildTypesTask/buildTypesTask.js\";\nimport { BuildError } from \"./error.js\";\nimport { jsFilesTask } from \"./tasks/jsFilesTask.js\";\nimport { binsTask } from \"./tasks/binsTask.js\";\nimport { detectModules } from \"./detectModules.js\";\nimport { disableLog, lineLog, log, okLog } from \"./log.js\";\nimport { runSettled } from \"./pipeline.js\";\nimport { type Args } from \"./args.js\";\nimport { viteTask } from \"./tasks/viteTask.js\";\nimport { promiseSettledResultErrors } from \"./promiseSettledResultErrors.js\";\n\nfunction setExports(\n exportsMap: Map<string, ExportsObject>,\n exportName: string,\n mapFn: (entry: ExportsObject) => ExportsObject,\n) {\n const entry = exportsMap.get(exportName) ?? ({} as ExportsObject);\n exportsMap.set(exportName, mapFn(entry));\n}\n\nexport async function defineViteConfig(args: Args = {}) {\n disableLog();\n const dirs = resolveDirs(args);\n const { sourceDir, outDir, packagePath } = dirs;\n\n await rm(outDir, { recursive: true, force: true });\n await mkdir(outDir, { recursive: true });\n const packageJson = await parsePackageJson({ sourceDir, packagePath });\n\n if (Array.isArray(packageJson)) {\n console.error(packageJson);\n throw new Error(\"Failed to parse package.json\");\n }\n\n const modulesResult = await detectModules(packageJson, dirs);\n if (modulesResult.error) {\n return { error: true, errors: modulesResult.errors };\n }\n const { modules } = modulesResult;\n const { viteConfig } = createViteConfig({
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/index.ts"],"sourcesContent":["import { relative } from \"node:path\";\nimport { mkdir, rm } from \"node:fs/promises\";\nimport { parsePackageJson } from \"./packageJson.js\";\nimport { type ExportsObject, writePackageJson } from \"./writePackageJson.js\";\nimport { resolveDirs } from \"./resolveDirs.js\";\nimport { createViteConfig } from \"./createViteConfig.js\";\nimport { copyStaticFilesTask } from \"./tasks/copyStaticFilesTask.js\";\nimport { buildTypesTask } from \"./tasks/buildTypesTask/buildTypesTask.js\";\nimport { BuildError } from \"./error.js\";\nimport { jsFilesTask } from \"./tasks/jsFilesTask.js\";\nimport { binsTask } from \"./tasks/binsTask.js\";\nimport { detectModules } from \"./detectModules.js\";\nimport { disableLog, lineLog, log, okLog } from \"./log.js\";\nimport { runSettled } from \"./pipeline.js\";\nimport { type Args } from \"./args.js\";\nimport { viteTask } from \"./tasks/viteTask.js\";\nimport { promiseSettledResultErrors } from \"./promiseSettledResultErrors.js\";\nimport { PrettyError } from \"./PrettyErrors.js\";\n\nfunction setExports(\n exportsMap: Map<string, ExportsObject>,\n exportName: string,\n mapFn: (entry: ExportsObject) => ExportsObject,\n) {\n const entry = exportsMap.get(exportName) ?? ({} as ExportsObject);\n exportsMap.set(exportName, mapFn(entry));\n}\n\nexport async function defineViteConfig(args: Args = {}) {\n disableLog();\n const dirs = resolveDirs(args);\n const { sourceDir, outDir, packagePath } = dirs;\n\n await rm(outDir, { recursive: true, force: true });\n await mkdir(outDir, { recursive: true });\n const packageJson = await parsePackageJson({ sourceDir, packagePath });\n\n if (Array.isArray(packageJson)) {\n console.error(packageJson);\n throw new Error(\"Failed to parse package.json\");\n }\n\n const modulesResult = await detectModules(packageJson, dirs);\n if (modulesResult.error) {\n return { error: true, errors: modulesResult.errors };\n }\n const { modules } = modulesResult;\n const { viteConfig } = createViteConfig({\n dirs,\n packageJson,\n modules,\n test: true,\n });\n\n return viteConfig;\n}\n\ntype RunResult =\n | {\n error: false;\n }\n | {\n error: true;\n errors: Array<string | PrettyError>;\n };\n\nexport async function run(args: Args): Promise<RunResult> {\n const dirs = resolveDirs(args);\n const { sourceDir, outDir, packagePath, outBinsDir } = dirs;\n\n await rm(outDir, { recursive: true, force: true });\n await mkdir(outDir, { recursive: true });\n const packageJson = await parsePackageJson({ sourceDir, packagePath });\n\n if (Array.isArray(packageJson)) {\n return { error: true, errors: packageJson };\n }\n\n const modulesResult = await detectModules(packageJson, dirs);\n if (modulesResult.error) {\n return { error: true, errors: modulesResult.errors };\n }\n const { modules } = modulesResult;\n const { viteConfig, entrypoints, bins } = createViteConfig({\n dirs,\n packageJson,\n modules,\n });\n\n const exportsMap = new Map<string, ExportsObject>();\n const binsMap = new Map<string, string>();\n\n const tasksRes = await runSettled(args, [\n copyStaticFilesTask(sourceDir, outDir),\n buildTypesTask({\n dirs,\n packageJson,\n entrypoints,\n modules,\n }).then(({ entrypointToEsDtsMap, entrypointToCjsDtsMap }) => {\n for (const [entrypoint, dts] of entrypointToEsDtsMap) {\n setExports(exportsMap, entrypoint, (entry) => {\n entry.dmts = \"./\" + relative(outDir, dts);\n return entry;\n });\n }\n\n for (const [entrypoint, dts] of entrypointToCjsDtsMap) {\n setExports(exportsMap, entrypoint, (entry) => {\n entry.dcts = \"./\" + relative(outDir, dts);\n return entry;\n });\n }\n }),\n viteTask({ viteConfig }).then((viteOutput) =>\n runSettled(args, [\n jsFilesTask({ buildOutput: viteOutput, entrypoints, outDir }).then(\n (res) => {\n for (const [filePath, name] of res) {\n setExports(exportsMap, name, (entry) => {\n const format = filePath.endsWith(\".js\") ? \"cjs\" : \"es\";\n if (format === \"es\") {\n entry.mjs = \"./\" + filePath;\n } else if (format === \"cjs\") {\n entry.cjs = \"./\" + filePath;\n }\n return entry;\n });\n }\n },\n ),\n binsTask({ outBinsDir, bins, buildOutput: viteOutput, outDir }).then(\n (res) => {\n for (const [value, key] of res) {\n binsMap.set(key, value);\n }\n },\n ),\n ]),\n ),\n ]);\n\n const errors = promiseSettledResultErrors(tasksRes).map((res) => {\n if (res instanceof PrettyError) {\n return res;\n }\n\n if (res instanceof BuildError) {\n return res.error;\n }\n\n return res.message;\n });\n\n if (errors.length > 0) {\n return { error: true, errors };\n }\n\n await writePackageJson(outDir, packageJson, {\n exportsMap,\n binsMap,\n });\n\n lineLog();\n log(`Build finished: ./${relative(sourceDir, outDir)}`);\n return { error: false };\n}\n"],"names":["disableLog","resolveDirs","rm","mkdir","packageJson","parsePackageJson","detectModules","createViteConfig","runSettled","copyStaticFilesTask","buildTypesTask","relative","viteTask","jsFilesTask","binsTask","promiseSettledResultErrors","PrettyError","BuildError","writePackageJson","lineLog","log"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmBA,SAAS,WACP,YACA,YACA,OACA;AACA,QAAM,QAAQ,WAAW,IAAI,UAAU,KAAM,CAAC;AAC9C,aAAW,IAAI,YAAY,MAAM,KAAK,CAAC;AACzC;AAEsB,eAAA,iBAAiB,OAAa,IAAI;AAC3CA,iB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A,QACAC,SAAA,SAAS,EAAE,YAAY,MAAM,aAAa,YAAY,OAAQ,CAAA,EAAE;AAAA,UAC9D,CAAC,QAAQ;AACP,uBAAW,CAAC,OAAO,GAAG,KAAK,KAAK;AACtB,sBAAA,IAAI,KAAK,KAAK;AAAA,YAAA;AAAA,UACxB;AAAA,QACF;AAAA,MAEH,CAAA;AAAA,IAAA;AAAA,EACH,CACD;AAED,QAAM,SAASC,2BAAAA,2BAA2B,QAAQ,EAAE,IAAI,CAAC,QAAQ;AAC/D,QAAI,eAAeC,aAAAA,aAAa;AACvB,aAAA;AAAA,IAAA;AAGT,QAAI,eAAeC,MAAAA,YAAY;AAC7B,aAAO,IAAI;AAAA,IAAA;AAGb,WAAO,IAAI;AAAA,EAAA,CACZ;AAEG,MAAA,OAAO,SAAS,GAAG;AACd,WAAA,EAAE,OAAO,MAAM,OAAO;AAAA,EAAA;AAGzB,QAAAC,iBAAA,iBAAiB,QAAQd,eAAa;AAAA,IAC1C;AAAA,IACA;AAAA,EAAA,CACD;AAEOe,cAAA;AACRC,MAAA,IAAI,qBAAqBT,KAAAA,SAAS,WAAW,MAAM,CAAC,EAAE;AAC/C,SAAA,EAAE,OAAO,MAAM;AACxB;;;"}
|
@@ -69,12 +69,8 @@ function babelPlugin({
|
|
69
69
|
};
|
70
70
|
},
|
71
71
|
buildEnd(error) {
|
72
|
-
if (
|
73
|
-
|
74
|
-
log.okLog("Babel");
|
75
|
-
}
|
76
|
-
} else {
|
77
|
-
this.error(error);
|
72
|
+
if (modules.babel && hasBabelConfig) {
|
73
|
+
log.okLog("Babel");
|
78
74
|
}
|
79
75
|
}
|
80
76
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","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.js","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":["findBabelConfig","path","okLog"],"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,MAAMA,gBAAA,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,UAAUC,gBAAK,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;AACnCC,YAAAA,MAAM,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
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
+
const PrettyErrors = require("../../PrettyErrors.js");
|
4
|
+
class ImportError extends PrettyErrors.PrettyError {
|
5
|
+
constructor(importName, path) {
|
6
|
+
super(
|
7
|
+
`ImportError: The "${importName}" library is marked as an optional dependency.
|
8
|
+
It cannot be imported directly in:
|
9
|
+
"${path ?? "unknown path"}"
|
10
|
+
|
11
|
+
To resolve this, consider:
|
12
|
+
1. Using a type import (e.g., 'import type').
|
13
|
+
2. Dynamically importing the library (e.g., 'await import("${importName}")').
|
14
|
+
|
15
|
+
This ensures compatibility with environments where "${importName}" is not installed.`
|
16
|
+
);
|
17
|
+
this.importName = importName;
|
18
|
+
this.path = path;
|
19
|
+
}
|
20
|
+
static async create(importName, path, fsReadFile) {
|
21
|
+
if (!path) {
|
22
|
+
return new ImportError(importName, path);
|
23
|
+
}
|
24
|
+
const content = await fsReadFile(path, "utf-8");
|
25
|
+
const lines = content.split("\n");
|
26
|
+
const affectedLine = lines.findIndex((line) => line.includes(importName));
|
27
|
+
const error = new ImportError(importName, path);
|
28
|
+
error.stack = `ImportError: you cannot import ${importName} because it marked as optional inside package.json
|
29
|
+
|
30
|
+
at ${path}:${affectedLine + 1}:0`;
|
31
|
+
return error;
|
32
|
+
}
|
33
|
+
}
|
34
|
+
exports.ImportError = ImportError;
|
35
|
+
//# sourceMappingURL=ImportError.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ImportError.js","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":["PrettyError"],"mappings":";;;AAEO,MAAM,oBAAoBA,aAAAA,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,89 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
+
const ImportError = require("./ImportError.js");
|
4
|
+
const fs = require("node:fs/promises");
|
5
|
+
function _interopNamespaceDefault(e) {
|
6
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
7
|
+
if (e) {
|
8
|
+
for (const k in e) {
|
9
|
+
if (k !== "default") {
|
10
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
11
|
+
Object.defineProperty(n, k, d.get ? d : {
|
12
|
+
enumerable: true,
|
13
|
+
get: () => e[k]
|
14
|
+
});
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
n.default = e;
|
19
|
+
return Object.freeze(n);
|
20
|
+
}
|
21
|
+
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
22
|
+
function isNodeModule(id) {
|
23
|
+
return id.startsWith("node:");
|
24
|
+
}
|
25
|
+
function importsPlugin(packageJson, test) {
|
26
|
+
var _a, _b;
|
27
|
+
if (test) {
|
28
|
+
return {
|
29
|
+
name: "smartbundle:imports"
|
30
|
+
};
|
31
|
+
}
|
32
|
+
const dynamicDeps = /* @__PURE__ */ new Set();
|
33
|
+
const staticDeps = /* @__PURE__ */ new Set();
|
34
|
+
for (const dep of Object.keys(packageJson.dependencies ?? {})) {
|
35
|
+
dynamicDeps.add(dep);
|
36
|
+
staticDeps.add(dep);
|
37
|
+
}
|
38
|
+
for (const dep of Object.keys(packageJson.peerDependencies ?? {})) {
|
39
|
+
if (!((_b = (_a = packageJson.peerDependenciesMeta) == null ? void 0 : _a[dep]) == null ? void 0 : _b.optional)) {
|
40
|
+
staticDeps.add(dep);
|
41
|
+
}
|
42
|
+
dynamicDeps.add(dep);
|
43
|
+
}
|
44
|
+
for (const dep of Object.keys(packageJson.optionalDependencies ?? {})) {
|
45
|
+
dynamicDeps.add(dep);
|
46
|
+
}
|
47
|
+
dynamicDeps.add(packageJson.name);
|
48
|
+
staticDeps.add(packageJson.name);
|
49
|
+
function createDepResolver(depsSet) {
|
50
|
+
return (id) => {
|
51
|
+
const segments = id.split("/");
|
52
|
+
let current = "";
|
53
|
+
for (const segment of segments) {
|
54
|
+
current += segment;
|
55
|
+
if (depsSet.has(current)) {
|
56
|
+
return true;
|
57
|
+
}
|
58
|
+
current += "/";
|
59
|
+
}
|
60
|
+
return false;
|
61
|
+
};
|
62
|
+
}
|
63
|
+
const dynamicDepResolver = createDepResolver(dynamicDeps);
|
64
|
+
const staticDepResolver = createDepResolver(staticDeps);
|
65
|
+
return {
|
66
|
+
name: "smartbundle:imports",
|
67
|
+
enforce: "pre",
|
68
|
+
async resolveId(id, importer) {
|
69
|
+
if (isNodeModule(id) || staticDepResolver(id)) {
|
70
|
+
return false;
|
71
|
+
}
|
72
|
+
if (dynamicDepResolver(id)) {
|
73
|
+
this.error(await ImportError.ImportError.create(id, importer, fs__namespace.readFile));
|
74
|
+
}
|
75
|
+
return null;
|
76
|
+
},
|
77
|
+
resolveDynamicImport(id) {
|
78
|
+
if (typeof id !== "string") {
|
79
|
+
return null;
|
80
|
+
}
|
81
|
+
if (isNodeModule(id) || dynamicDepResolver(id)) {
|
82
|
+
return false;
|
83
|
+
}
|
84
|
+
return null;
|
85
|
+
}
|
86
|
+
};
|
87
|
+
}
|
88
|
+
exports.importsPlugin = importsPlugin;
|
89
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","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":["ImportError","fs"],"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,MAAMA,wBAAY,OAAO,IAAI,UAAUC,cAAG,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;;"}
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
function promiseSettledResultErrors(results) {
|
4
4
|
const errors = [];
|
5
5
|
for (const result of results) {
|
6
|
-
if (result
|
6
|
+
if (Array.isArray(result)) {
|
7
7
|
errors.push(promiseSettledResultErrors(result));
|
8
8
|
} else if (result.status === "rejected") {
|
9
9
|
errors.push(result.reason);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"promiseSettledResultErrors.js","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.js","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,11 +1,20 @@
|
|
1
1
|
"use strict";
|
2
2
|
const args = require("./args.js");
|
3
3
|
const _ = require("./index.js");
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
const PrettyErrors = require("./PrettyErrors.js");
|
5
|
+
const youch$1 = require("youch");
|
6
|
+
const youch = new youch$1.Youch();
|
7
|
+
(async () => {
|
8
|
+
const res = await _.run(args.args);
|
9
|
+
if (!res.error) {
|
10
|
+
return;
|
11
|
+
}
|
12
|
+
for (const error of res.errors) {
|
13
|
+
if (!(error instanceof PrettyErrors.PrettyError)) {
|
7
14
|
console.error("\x1B[31m[ERROR]", error, "\x1B[0m");
|
15
|
+
continue;
|
8
16
|
}
|
17
|
+
console.error(await youch.toANSI(error));
|
9
18
|
}
|
10
|
-
});
|
19
|
+
})();
|
11
20
|
//# sourceMappingURL=run.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"run.js","sources":["../../../../src/run.ts"],"sourcesContent":["import { args } from \"./args.js\";\nimport { run } from \"./index.js\";\n\
|
1
|
+
{"version":3,"file":"run.js","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":["Youch","run","args","PrettyError"],"mappings":";;;;;AAKA,MAAM,QAAQ,IAAIA,QAAAA,MAAM;AAAA,CAEvB,YAAY;AACL,QAAA,MAAM,MAAMC,EAAA,IAAIC,SAAI;AAEtB,MAAA,CAAC,IAAI,OAAO;AACd;AAAA,EAAA;AAGS,aAAA,SAAS,IAAI,QAAQ;AAC1B,QAAA,EAAE,iBAAiBC,aAAAA,cAAc;AAC3B,cAAA,MAAM,mBAAmB,OAAO,SAAS;AACjD;AAAA,IAAA;AAGF,YAAQ,MAAM,MAAM,MAAM,OAAO,KAAK,CAAC;AAAA,EAAA;AAE3C,GAAG;"}
|
@@ -90,6 +90,7 @@ async function callTypescript({
|
|
90
90
|
const esmEntrypoint = sourceToEsmDtsMap.get(sourceEntrypoint);
|
91
91
|
if (esmEntrypoint) {
|
92
92
|
const localPackages = findTypingsNames.findTypingsNames(
|
93
|
+
ts,
|
93
94
|
esmEntrypoint,
|
94
95
|
esmOutDir,
|
95
96
|
".d.mts"
|
@@ -100,13 +101,19 @@ async function callTypescript({
|
|
100
101
|
}
|
101
102
|
const cjsEntrypoint = sourceToCjsDtsMap.get(sourceEntrypoint);
|
102
103
|
if (cjsEntrypoint) {
|
103
|
-
const localPackages = findTypingsNames.findTypingsNames(
|
104
|
+
const localPackages = findTypingsNames.findTypingsNames(
|
105
|
+
ts,
|
106
|
+
cjsEntrypoint,
|
107
|
+
cjsOutDir,
|
108
|
+
".d.ts"
|
109
|
+
);
|
104
110
|
for (const p of localPackages) {
|
105
111
|
packages.add(p);
|
106
112
|
}
|
107
113
|
}
|
108
114
|
}
|
109
115
|
const { missingTypings, existingTypingPackages } = findTypingsPackages.findTypingsPackages(
|
116
|
+
ts,
|
110
117
|
packages,
|
111
118
|
sourceDir
|
112
119
|
);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"callTypescript.js","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.js","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":["path","fs","inlineExtensionsCjs","inlineExtensionsMjs","findTypingsNames","findTypingsPackages","getMinVersion","BuildError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,SAAS,eAAe,QAAgB,UAAkB;AACxD,SAAO,CAAC,MAAc;AACpB,UAAM,MAAMA,gBAAK,KAAK,QAAQA,gBAAK,QAAQ,QAAQ,CAAC;AACpD,WAAOC,cAAG,WAAWD,gBAAK,KAAK,KAAK,CAAC,CAAC;AAAA,EACxC;AACF;AAEA,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAsB;AACpB,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AAAA,QACH;AAAA,QACA,eAAe,QAAQ,YAAY;AAAA,MACrC;AACGF,oBAAA,cAAc,MAAM,eAAe;AAAA,IAAA;AAAA,EACxC;AAKI,QAAA,+BAAe,IAAY;AACjC,aAAW,oBAAoB,eAAe;AACtC,UAAA,gBAAgB,kBAAkB,IAAI,gBAAgB;AAC5D,QAAI,eAAe;AACjB,YAAM,gBAAgBG,iBAAA;AAAA,QACpB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,iBAAW,KAAK,eAAe;AAC7B,iBAAS,IAAI,CAAC;AAAA,MAAA;AAAA,IAChB;AAGI,UAAA,gBAAgB,kBAAkB,IAAI,gBAAgB;AAC5D,QAAI,eAAe;AACjB,YAAM,gBAAgBA,iBAAA;AAAA,QACpB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,iBAAW,KAAK,eAAe;AAC7B,iBAAS,IAAI,CAAC;AAAA,MAAA;AAAA,IAChB;AAAA,EACF;AAKI,QAAA,EAAE,gBAAgB,uBAAA,IAA2BC,oBAAA;AAAA,IACjD;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,aAAW,OAAO,wBAAwB;AAEtC,QAAAC,cAAA,cAAc,aAAa,KAAK;AAAA,MAC9B;AAAA,MACA;AAAA,IACD,CAAA,KAAK,MACN;AACA,qBAAe,IAAI,GAAG;AAAA,IAAA;AAAA,EACxB;AAEE,MAAA,eAAe,OAAO,GAAG;AAC3B,UAAM,WAAW,CAAC,GAAG,cAAc,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,GAAG,EAAE,KAAK,IAAI;AACnE,UAAM,IAAIC,MAAA;AAAA,MACR,mDAAmD,QAAQ;AAAA,IAC7D;AAAA,EAAA;AAIK,SAAA;AAAA,IACL;AAAA,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,29 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
-
const ts = require("typescript");
|
4
3
|
const path = require("node:path");
|
5
4
|
const fs = require("node:fs");
|
6
|
-
function
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
if (k !== "default") {
|
11
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
12
|
-
Object.defineProperty(n, k, d.get ? d : {
|
13
|
-
enumerable: true,
|
14
|
-
get: () => e[k]
|
15
|
-
});
|
16
|
-
}
|
17
|
-
}
|
18
|
-
}
|
19
|
-
n.default = e;
|
20
|
-
return Object.freeze(n);
|
21
|
-
}
|
22
|
-
const ts__namespace = /* @__PURE__ */ _interopNamespaceDefault(ts);
|
23
|
-
function createCompilerHostWithVirtualSource(sourceDir) {
|
24
|
-
return ts__namespace.createCompilerHost({
|
25
|
-
target: ts__namespace.ScriptTarget.ESNext,
|
26
|
-
moduleResolution: ts__namespace.ModuleResolutionKind.NodeNext,
|
5
|
+
function createCompilerHostWithVirtualSource(ts, sourceDir) {
|
6
|
+
return ts.createCompilerHost({
|
7
|
+
target: ts.ScriptTarget.ESNext,
|
8
|
+
moduleResolution: ts.ModuleResolutionKind.NodeNext,
|
27
9
|
baseUrl: ".",
|
28
10
|
sourceRoot: sourceDir,
|
29
11
|
noEmit: true,
|
@@ -44,9 +26,9 @@ function collectAllFilesInDir(sourceDir, ext) {
|
|
44
26
|
}
|
45
27
|
return ret;
|
46
28
|
}
|
47
|
-
function findTypingsNames(entrypoint, sourceDir, ext) {
|
48
|
-
const host = createCompilerHostWithVirtualSource(sourceDir);
|
49
|
-
const program =
|
29
|
+
function findTypingsNames({ ts }, entrypoint, sourceDir, ext) {
|
30
|
+
const host = createCompilerHostWithVirtualSource(ts, sourceDir);
|
31
|
+
const program = ts.createProgram({
|
50
32
|
rootNames: collectAllFilesInDir(sourceDir, ext),
|
51
33
|
options: {},
|
52
34
|
host
|
@@ -64,16 +46,16 @@ function findTypingsNames(entrypoint, sourceDir, ext) {
|
|
64
46
|
}
|
65
47
|
while (filesQueue.length > 0) {
|
66
48
|
let visit = function(node) {
|
67
|
-
if (
|
49
|
+
if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {
|
68
50
|
processModuleSpecifier(node.moduleSpecifier);
|
69
51
|
}
|
70
|
-
if (
|
52
|
+
if (ts.isImportTypeNode(node) && ts.isLiteralTypeNode(node.argument) && ts.isStringLiteral(node.argument.literal)) {
|
71
53
|
processModuleSpecifier(node.argument.literal);
|
72
54
|
}
|
73
|
-
if (
|
55
|
+
if (ts.isExportDeclaration(node) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
|
74
56
|
processModuleSpecifier(node.moduleSpecifier);
|
75
57
|
}
|
76
|
-
|
58
|
+
ts.forEachChild(node, visit);
|
77
59
|
};
|
78
60
|
const relativeCurrentFile = filesQueue.pop();
|
79
61
|
const currentFile = path.join(sourceDir, relativeCurrentFile);
|
@@ -81,7 +63,7 @@ function findTypingsNames(entrypoint, sourceDir, ext) {
|
|
81
63
|
const sourceFile = program.getSourceFile(currentFile);
|
82
64
|
if (!sourceFile) continue;
|
83
65
|
processedFiles.add(currentFile);
|
84
|
-
|
66
|
+
ts.forEachChild(sourceFile, visit);
|
85
67
|
}
|
86
68
|
return packages;
|
87
69
|
}
|