smartbundle 0.11.0-alpha.1 → 0.11.0-alpha.2
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/buildVite.d.ts +1 -1
- package/__compiled__/cjs/src/buildVite.js.map +1 -1
- package/__compiled__/cjs/src/createViteConfig.d.ts +3 -1
- package/__compiled__/cjs/src/createViteConfig.js +10 -2
- package/__compiled__/cjs/src/createViteConfig.js.map +1 -1
- package/__compiled__/cjs/src/detectModules.d.ts +7 -0
- package/__compiled__/cjs/src/detectModules.js +74 -0
- package/__compiled__/cjs/src/detectModules.js.map +1 -0
- package/__compiled__/cjs/src/index.js +19 -4
- package/__compiled__/cjs/src/index.js.map +1 -1
- package/__compiled__/cjs/src/log.d.ts +5 -0
- package/__compiled__/cjs/src/log.js +26 -0
- package/__compiled__/cjs/src/log.js.map +1 -0
- package/__compiled__/cjs/src/plugins/babel/index.d.ts +4 -2
- package/__compiled__/cjs/src/plugins/babel/index.js +20 -36
- package/__compiled__/cjs/src/plugins/babel/index.js.map +1 -1
- package/__compiled__/cjs/src/plugins/react/index.d.ts +4 -4
- package/__compiled__/cjs/src/plugins/react/index.js +15 -10
- package/__compiled__/cjs/src/plugins/react/index.js.map +1 -1
- package/__compiled__/cjs/src/tasks/binsTask.d.ts +1 -1
- package/__compiled__/cjs/src/tasks/binsTask.js +4 -1
- package/__compiled__/cjs/src/tasks/binsTask.js.map +1 -1
- package/__compiled__/cjs/src/tasks/buildTypesTask/buildTypesTask.d.ts +3 -1
- package/__compiled__/cjs/src/tasks/buildTypesTask/buildTypesTask.js +11 -32
- package/__compiled__/cjs/src/tasks/buildTypesTask/buildTypesTask.js.map +1 -1
- package/__compiled__/cjs/src/tasks/buildTypesTask/callTypescript.js +14 -2
- package/__compiled__/cjs/src/tasks/buildTypesTask/callTypescript.js.map +1 -1
- package/__compiled__/cjs/src/tasks/buildTypesTask/inlineExtensions.d.ts +3 -2
- package/__compiled__/cjs/src/tasks/buildTypesTask/inlineExtensions.js +13 -8
- package/__compiled__/cjs/src/tasks/buildTypesTask/inlineExtensions.js.map +1 -1
- package/__compiled__/cjs/src/tasks/copyStaticFilesTask.d.ts +1 -1
- package/__compiled__/cjs/src/tasks/copyStaticFilesTask.js +7 -1
- package/__compiled__/cjs/src/tasks/copyStaticFilesTask.js.map +1 -1
- package/__compiled__/cjs/src/tasks/jsFilesTask.d.ts +1 -1
- package/__compiled__/cjs/src/tasks/jsFilesTask.js +2 -1
- package/__compiled__/cjs/src/tasks/jsFilesTask.js.map +1 -1
- package/__compiled__/cjs/src/writePackageJson.js +2 -0
- package/__compiled__/cjs/src/writePackageJson.js.map +1 -1
- package/__compiled__/esm/src/buildVite.d.mts +1 -1
- package/__compiled__/esm/src/buildVite.mjs.map +1 -1
- package/__compiled__/esm/src/createViteConfig.d.mts +3 -1
- package/__compiled__/esm/src/createViteConfig.mjs +10 -2
- package/__compiled__/esm/src/createViteConfig.mjs.map +1 -1
- package/__compiled__/esm/src/detectModules.d.mts +7 -0
- package/__compiled__/esm/src/detectModules.mjs +52 -0
- package/__compiled__/esm/src/detectModules.mjs.map +1 -0
- package/__compiled__/esm/src/index.mjs +19 -4
- package/__compiled__/esm/src/index.mjs.map +1 -1
- package/__compiled__/esm/src/log.d.mts +5 -0
- package/__compiled__/esm/src/log.mjs +26 -0
- package/__compiled__/esm/src/log.mjs.map +1 -0
- package/__compiled__/esm/src/plugins/babel/index.d.mts +4 -2
- package/__compiled__/esm/src/plugins/babel/index.mjs +20 -14
- package/__compiled__/esm/src/plugins/babel/index.mjs.map +1 -1
- package/__compiled__/esm/src/plugins/react/index.d.mts +4 -4
- package/__compiled__/esm/src/plugins/react/index.mjs +15 -10
- package/__compiled__/esm/src/plugins/react/index.mjs.map +1 -1
- package/__compiled__/esm/src/tasks/binsTask.d.mts +1 -1
- package/__compiled__/esm/src/tasks/binsTask.mjs +4 -1
- package/__compiled__/esm/src/tasks/binsTask.mjs.map +1 -1
- package/__compiled__/esm/src/tasks/buildTypesTask/buildTypesTask.d.mts +3 -1
- package/__compiled__/esm/src/tasks/buildTypesTask/buildTypesTask.mjs +11 -10
- package/__compiled__/esm/src/tasks/buildTypesTask/buildTypesTask.mjs.map +1 -1
- package/__compiled__/esm/src/tasks/buildTypesTask/callTypescript.mjs +14 -2
- package/__compiled__/esm/src/tasks/buildTypesTask/callTypescript.mjs.map +1 -1
- package/__compiled__/esm/src/tasks/buildTypesTask/inlineExtensions.d.mts +3 -2
- package/__compiled__/esm/src/tasks/buildTypesTask/inlineExtensions.mjs +13 -8
- package/__compiled__/esm/src/tasks/buildTypesTask/inlineExtensions.mjs.map +1 -1
- package/__compiled__/esm/src/tasks/copyStaticFilesTask.d.mts +1 -1
- package/__compiled__/esm/src/tasks/copyStaticFilesTask.mjs +7 -1
- package/__compiled__/esm/src/tasks/copyStaticFilesTask.mjs.map +1 -1
- package/__compiled__/esm/src/tasks/jsFilesTask.d.mts +1 -1
- package/__compiled__/esm/src/tasks/jsFilesTask.mjs +2 -1
- package/__compiled__/esm/src/tasks/jsFilesTask.mjs.map +1 -1
- package/__compiled__/esm/src/writePackageJson.mjs +2 -0
- package/__compiled__/esm/src/writePackageJson.mjs.map +1 -1
- package/package.json +1 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buildVite.js","sources":["../../../../src/buildVite.ts"],"sourcesContent":["import { build, type UserConfig, Rollup } from \"vite\";\nimport { errors } from \"./errors.js\";\n\ntype BuildViteOptions = {\n viteConfig: UserConfig;\n};\n\ntype BuildSuccess = {\n error: false;\n output: Rollup.OutputChunk[];\n};\ntype BuildError = {\n error: true;\n errors: Array<string>;\n};\n\ntype BuildResult = BuildSuccess | BuildError;\n\nexport async function buildVite({\n viteConfig,\n}: BuildViteOptions): 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 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"],"names":["build","errors","x"],"mappings":";;;;AAkBA,eAAsB,UAAU;AAAA,EAC9B;AACF,GAA2C;AACrC,MAAA;AACI,UAAA,UAAU,MAAMA,WAAM,UAAU;AACtC,QAAI,CAAC,MAAM,QAAQ,OAAO,GAAG;AACpB,aAAA;AAAA,QACL,OAAO;AAAA,QACP,QAAQ,CAACC,OAAA,OAAO,WAAW;AAAA,MAAA;AAAA,IAE/B;AAEO,WAAA;AAAA,MACL,OAAO;AAAA,MACP,QAAQ,QAAQ;AAAA,QAAQ,CAAC,MACvB,EAAE,OAAO,OAAO,CAACC,OAAMA,GAAE,SAAS,OAAO;AAAA,MAC3C;AAAA,IAAA;AAAA,WAEK,GAAG;AACV,QAAI,aAAa,OAAO;AACf,aAAA;AAAA,QACL,OAAO;AAAA,QACP,QAAQ,CAAC,EAAE,OAAO;AAAA,MAAA;AAAA,IAEtB;AAAA,EACF;AACO,SAAA;AAAA,IACL,OAAO;AAAA,IACP,QAAQ,CAACD,OAAA,OAAO,WAAW;AAAA,EAAA;AAE/B;;"}
|
1
|
+
{"version":3,"file":"buildVite.js","sources":["../../../../src/buildVite.ts"],"sourcesContent":["import { build, type UserConfig, type Rollup } from \"vite\";\nimport { errors } from \"./errors.js\";\n\ntype BuildViteOptions = {\n viteConfig: UserConfig;\n};\n\ntype BuildSuccess = {\n error: false;\n output: Rollup.OutputChunk[];\n};\ntype BuildError = {\n error: true;\n errors: Array<string>;\n};\n\ntype BuildResult = BuildSuccess | BuildError;\n\nexport async function buildVite({\n viteConfig,\n}: BuildViteOptions): 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 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"],"names":["build","errors","x"],"mappings":";;;;AAkBA,eAAsB,UAAU;AAAA,EAC9B;AACF,GAA2C;AACrC,MAAA;AACI,UAAA,UAAU,MAAMA,WAAM,UAAU;AACtC,QAAI,CAAC,MAAM,QAAQ,OAAO,GAAG;AACpB,aAAA;AAAA,QACL,OAAO;AAAA,QACP,QAAQ,CAACC,OAAA,OAAO,WAAW;AAAA,MAAA;AAAA,IAE/B;AAEO,WAAA;AAAA,MACL,OAAO;AAAA,MACP,QAAQ,QAAQ;AAAA,QAAQ,CAAC,MACvB,EAAE,OAAO,OAAO,CAACC,OAAMA,GAAE,SAAS,OAAO;AAAA,MAC3C;AAAA,IAAA;AAAA,WAEK,GAAG;AACV,QAAI,aAAa,OAAO;AACf,aAAA;AAAA,QACL,OAAO;AAAA,QACP,QAAQ,CAAC,EAAE,OAAO;AAAA,MAAA;AAAA,IAEtB;AAAA,EACF;AACO,SAAA;AAAA,IACL,OAAO;AAAA,IACP,QAAQ,CAACD,OAAA,OAAO,WAAW;AAAA,EAAA;AAE/B;;"}
|
@@ -1,10 +1,12 @@
|
|
1
1
|
import { type Dirs } from "./resolveDirs.js";
|
2
2
|
import { type PackageJson } from "./packageJson.js";
|
3
|
+
import { type DetectedModules } from "./detectModules.js";
|
3
4
|
type CreateViteConfigParam = {
|
4
5
|
dirs: Dirs;
|
5
6
|
packageJson: PackageJson;
|
7
|
+
modules: DetectedModules;
|
6
8
|
};
|
7
|
-
export declare function createViteConfig({ dirs, packageJson }: CreateViteConfigParam): {
|
9
|
+
export declare function createViteConfig({ dirs, packageJson, modules, }: CreateViteConfigParam): {
|
8
10
|
viteConfig: import("vite").UserConfig;
|
9
11
|
entrypoints: Map<string, string>;
|
10
12
|
bins: Map<string, string>;
|
@@ -6,6 +6,7 @@ require("zod");
|
|
6
6
|
const vite = require("vite");
|
7
7
|
const index$1 = require("./plugins/babel/index.js");
|
8
8
|
const index = require("./plugins/react/index.js");
|
9
|
+
require("semver");
|
9
10
|
function mapToObject(map) {
|
10
11
|
const obj = {};
|
11
12
|
for (const [key, value] of map) {
|
@@ -41,7 +42,11 @@ function createExternalDepValidator(packageJson) {
|
|
41
42
|
return false;
|
42
43
|
};
|
43
44
|
}
|
44
|
-
function createViteConfig({
|
45
|
+
function createViteConfig({
|
46
|
+
dirs,
|
47
|
+
packageJson,
|
48
|
+
modules
|
49
|
+
}) {
|
45
50
|
const { sourceDir, outDir } = dirs;
|
46
51
|
const entrypoints = /* @__PURE__ */ new Map();
|
47
52
|
if (packageJson.exports) {
|
@@ -59,7 +64,10 @@ function createViteConfig({ dirs, packageJson }) {
|
|
59
64
|
const mergedEntries = new Map([...entrypoints, ...bins]);
|
60
65
|
const depsValidator = createExternalDepValidator(packageJson);
|
61
66
|
const viteConfig = vite.defineConfig({
|
62
|
-
plugins: [
|
67
|
+
plugins: [
|
68
|
+
index.reactPlugin({ modules }),
|
69
|
+
index$1.babelPlugin({ packageJson, dirs, modules })
|
70
|
+
],
|
63
71
|
publicDir: false,
|
64
72
|
root: sourceDir,
|
65
73
|
logLevel: "silent",
|
@@ -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\";\n\ntype CreateViteConfigParam = {\n dirs: Dirs;\n packageJson: PackageJson;\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\nfunction createExternalDepValidator(packageJson: PackageJson) {\n const allExternalPackages = new Set();\n for (const key of [\n \"dependencies\",\n \"optionalDependencies\",\n \"peerDependencies\",\n ] as const) {\n for (const dep of Object.keys(packageJson[key] ?? {})) {\n allExternalPackages.add(dep);\n }\n }\n allExternalPackages.add(packageJson.name);\n\n return (id: string) => {\n if (id.startsWith(\"node:\")) {\n return true;\n }\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 (allExternalPackages.has(current)) {\n return true;\n }\n current += \"/\";\n }\n return false;\n };\n}\n\nexport function createViteConfig({
|
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\nfunction createExternalDepValidator(packageJson: PackageJson) {\n const allExternalPackages = new Set();\n for (const key of [\n \"dependencies\",\n \"optionalDependencies\",\n \"peerDependencies\",\n ] as const) {\n for (const dep of Object.keys(packageJson[key] ?? {})) {\n allExternalPackages.add(dep);\n }\n }\n allExternalPackages.add(packageJson.name);\n\n return (id: string) => {\n if (id.startsWith(\"node:\")) {\n return true;\n }\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 (allExternalPackages.has(current)) {\n return true;\n }\n current += \"/\";\n }\n return false;\n };\n}\n\nexport function createViteConfig({\n dirs,\n packageJson,\n modules,\n}: CreateViteConfigParam) {\n const { sourceDir, outDir } = 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 depsValidator = createExternalDepValidator(packageJson);\n\n const viteConfig = defineConfig({\n plugins: [\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(\"__compiled__\", \"esm\", `${noExt}.mjs`);\n } else {\n return join(\"__compiled__\", \"cjs\", `${noExt}.js`);\n }\n }\n\n if (format === \"es\") {\n return join(\n \"__compiled__\",\n \"esm\",\n relative(sourceDir, entrypoint).replace(/\\.[^.]+$/, \"\") + \".mjs\",\n );\n } else {\n return join(\n \"__compiled__\",\n \"cjs\",\n relative(sourceDir, entrypoint).replace(/\\.[^.]+$/, \"\") + \".js\",\n );\n }\n },\n },\n rollupOptions: {\n external: depsValidator,\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","defineConfig","reactPlugin","babelPlugin","relative"],"mappings":";;;;;;;;;AAcA,SAAS,YAAY,KAA0B;AAC7C,QAAM,MAA8B,CAAA;AACpC,aAAW,CAAC,KAAK,KAAK,KAAK,KAAK;AAC9B,QAAI,GAAG,IA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0,0 +1,7 @@
|
|
1
|
+
import { type PackageJson } from "./packageJson.js";
|
2
|
+
export type DetectedModules = {
|
3
|
+
ts?: typeof import("typescript");
|
4
|
+
babel?: typeof import("@babel/core");
|
5
|
+
react?: "legacy" | "modern";
|
6
|
+
};
|
7
|
+
export declare function detectModules(packageJson: PackageJson): Promise<DetectedModules>;
|
@@ -0,0 +1,74 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
10
|
+
for (let key of __getOwnPropNames(from))
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
13
|
+
}
|
14
|
+
return to;
|
15
|
+
};
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
22
|
+
mod
|
23
|
+
));
|
24
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
25
|
+
require("node:fs/promises");
|
26
|
+
require("zod");
|
27
|
+
require("node:path");
|
28
|
+
const semver = require("semver");
|
29
|
+
const log = require("./log.js");
|
30
|
+
async function detectBabel(packageJson) {
|
31
|
+
if ("@babel/core" in (packageJson.optionalDependencies ?? {})) {
|
32
|
+
log.errorLog("babel excluded because inside optionalDependencies");
|
33
|
+
return;
|
34
|
+
}
|
35
|
+
try {
|
36
|
+
const babel = await import("@babel/core");
|
37
|
+
log.okLog("babel, version:", babel.version);
|
38
|
+
return babel;
|
39
|
+
} catch {
|
40
|
+
log.errorLog("babel");
|
41
|
+
}
|
42
|
+
}
|
43
|
+
async function detectReact(packageJson) {
|
44
|
+
var _a, _b, _c;
|
45
|
+
const reactVersion = ((_a = packageJson.dependencies) == null ? void 0 : _a.react) ?? ((_b = packageJson.devDependencies) == null ? void 0 : _b.react) ?? ((_c = packageJson.optionalDependencies) == null ? void 0 : _c.react);
|
46
|
+
if (reactVersion) {
|
47
|
+
const minReactVersion = semver.minVersion(reactVersion);
|
48
|
+
if (minReactVersion) {
|
49
|
+
const isLegacy = semver.lt(minReactVersion, "17.0.0");
|
50
|
+
const transform = isLegacy ? "legacy" : "modern";
|
51
|
+
log.okLog(
|
52
|
+
`react, min version: ${minReactVersion.version}. Transform: ${transform}`
|
53
|
+
);
|
54
|
+
return transform;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
log.errorLog("react");
|
58
|
+
}
|
59
|
+
async function detectModules(packageJson) {
|
60
|
+
const result = {};
|
61
|
+
log.log("Detecting modules");
|
62
|
+
try {
|
63
|
+
result.ts = (await import("typescript")).default;
|
64
|
+
log.okLog("typescript, version:", result.ts.version);
|
65
|
+
} catch {
|
66
|
+
log.errorLog("typescript");
|
67
|
+
}
|
68
|
+
result.babel = await detectBabel(packageJson);
|
69
|
+
result.react = await detectReact(packageJson);
|
70
|
+
log.lineLog();
|
71
|
+
return result;
|
72
|
+
}
|
73
|
+
exports.detectModules = detectModules;
|
74
|
+
//# sourceMappingURL=detectModules.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"detectModules.js","sources":["../../../../src/detectModules.ts"],"sourcesContent":["import { type PackageJson } from \"./packageJson.js\";\nimport semver from \"semver\";\nimport { okLog, errorLog, log, lineLog } from \"./log.js\";\n\nexport type DetectedModules = {\n ts?: typeof import(\"typescript\");\n babel?: typeof import(\"@babel/core\");\n react?: \"legacy\" | \"modern\";\n};\n\nasync function detectBabel(\n packageJson: PackageJson,\n): Promise<typeof import(\"@babel/core\") | undefined> {\n if (\"@babel/core\" in (packageJson.optionalDependencies ?? {})) {\n errorLog(\"babel excluded because inside optionalDependencies\");\n return;\n }\n\n try {\n const babel = await import(\"@babel/core\");\n okLog(\"babel, version:\", babel.version);\n return babel;\n } catch {\n errorLog(\"babel\");\n }\n}\n\nasync function detectReact(\n packageJson: PackageJson,\n): Promise<\"legacy\" | \"modern\" | undefined> {\n const reactVersion =\n packageJson.dependencies?.react ??\n packageJson.devDependencies?.react ??\n packageJson.optionalDependencies?.react;\n if (reactVersion) {\n const minReactVersion = semver.minVersion(reactVersion);\n if (minReactVersion) {\n const isLegacy = semver.lt(minReactVersion, \"17.0.0\");\n const transform = isLegacy ? \"legacy\" : \"modern\";\n okLog(\n `react, min version: ${minReactVersion.version}. Transform: ${transform}`,\n );\n return transform;\n }\n }\n errorLog(\"react\");\n}\n\nexport async function detectModules(\n packageJson: PackageJson,\n): Promise<DetectedModules> {\n const result: DetectedModules = {};\n log(\"Detecting modules\");\n try {\n // ts <=4.3 has no named exports. The all methods is located in the default export\n result.ts = (await import(\"typescript\")).default;\n okLog(\"typescript, version:\", result.ts.version);\n } catch {\n errorLog(\"typescript\");\n }\n\n result.babel = await detectBabel(packageJson);\n result.react = await detectReact(packageJson);\n\n lineLog();\n return result;\n}\n"],"names":["errorLog","okLog","log","lineLog"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,eAAe,YACb,aACmD;AACnD,MAAI,kBAAkB,YAAY,wBAAwB,CAAK,IAAA;AAC7DA,QAAA,SAAS,oDAAoD;AAC7D;AAAA,EACF;AAEI,MAAA;AACI,UAAA,QAAQ,MAAM,OAAO,aAAa;AAClCC,QAAAA,MAAA,mBAAmB,MAAM,OAAO;AAC/B,WAAA;AAAA,EAAA,QACD;AACND,QAAA,SAAS,OAAO;AAAA,EAClB;AACF;AAEA,eAAe,YACb,aAC0C;;AACpC,QAAA,iBACJ,iBAAY,iBAAZ,mBAA0B,YAC1B,iBAAY,oBAAZ,mBAA6B,YAC7B,iBAAY,yBAAZ,mBAAkC;AACpC,MAAI,cAAc;AACV,UAAA,kBAAkB,OAAO,WAAW,YAAY;AACtD,QAAI,iBAAiB;AACnB,YAAM,WAAW,OAAO,GAAG,iBAAiB,QAAQ;AAC9C,YAAA,YAAY,WAAW,WAAW;AACxCC,UAAA;AAAA,QACE,uBAAuB,gBAAgB,OAAO,gBAAgB,SAAS;AAAA,MAAA;AAElE,aAAA;AAAA,IACT;AAAA,EACF;AACAD,MAAA,SAAS,OAAO;AAClB;AAEA,eAAsB,cACpB,aAC0B;AAC1B,QAAM,SAA0B,CAAA;AAChCE,MAAA,IAAI,mBAAmB;AACnB,MAAA;AAEF,WAAO,MAAM,MAAM,OAAO,YAAY,GAAG;AACnCD,QAAAA,MAAA,wBAAwB,OAAO,GAAG,OAAO;AAAA,EAAA,QACzC;AACND,QAAA,SAAS,YAAY;AAAA,EACvB;AAEO,SAAA,QAAQ,MAAM,YAAY,WAAW;AACrC,SAAA,QAAQ,MAAM,YAAY,WAAW;AAEpCG,MAAAA;AACD,SAAA;AACT;;"}
|
@@ -12,11 +12,14 @@ const buildTypesTask = require("./tasks/buildTypesTask/buildTypesTask.js");
|
|
12
12
|
const error = require("./error.js");
|
13
13
|
const jsFilesTask = require("./tasks/jsFilesTask.js");
|
14
14
|
const binsTask = require("./tasks/binsTask.js");
|
15
|
+
const detectModules = require("./detectModules.js");
|
16
|
+
const log = require("./log.js");
|
15
17
|
function setExports(exportsMap, exportName, mapFn) {
|
16
18
|
const entry = exportsMap.get(exportName) ?? {};
|
17
19
|
exportsMap.set(exportName, mapFn(entry));
|
18
20
|
}
|
19
21
|
async function defineViteConfig(args = {}) {
|
22
|
+
log.disableLog();
|
20
23
|
const dirs = resolveDirs.resolveDirs(args);
|
21
24
|
const { sourceDir, outDir, packagePath } = dirs;
|
22
25
|
await fs.rm(outDir, { recursive: true, force: true });
|
@@ -26,7 +29,8 @@ async function defineViteConfig(args = {}) {
|
|
26
29
|
console.error(packageJson$1);
|
27
30
|
throw new Error("Failed to parse package.json");
|
28
31
|
}
|
29
|
-
const
|
32
|
+
const modules = await detectModules.detectModules(packageJson$1);
|
33
|
+
const { viteConfig } = createViteConfig.createViteConfig({ dirs, packageJson: packageJson$1, modules });
|
30
34
|
return viteConfig;
|
31
35
|
}
|
32
36
|
async function run(args) {
|
@@ -38,10 +42,13 @@ async function run(args) {
|
|
38
42
|
if (Array.isArray(packageJson$1)) {
|
39
43
|
return { error: true, errors: packageJson$1 };
|
40
44
|
}
|
45
|
+
const modules = await detectModules.detectModules(packageJson$1);
|
41
46
|
const { viteConfig, entrypoints, bins } = createViteConfig.createViteConfig({
|
42
47
|
dirs,
|
43
|
-
packageJson: packageJson$1
|
48
|
+
packageJson: packageJson$1,
|
49
|
+
modules
|
44
50
|
});
|
51
|
+
log.okLog("Vite");
|
45
52
|
const outputs = await buildVite.buildVite({ viteConfig });
|
46
53
|
if (outputs.error) {
|
47
54
|
return { error: true, errors: outputs.errors };
|
@@ -55,7 +62,8 @@ async function run(args) {
|
|
55
62
|
sourceDir,
|
56
63
|
outDir,
|
57
64
|
entrypoints,
|
58
|
-
buildOutput: viteOutput
|
65
|
+
buildOutput: viteOutput,
|
66
|
+
modules
|
59
67
|
}).then((res) => {
|
60
68
|
for (const [types, source] of res) {
|
61
69
|
setExports(exportsMap, source, (entry) => {
|
@@ -92,7 +100,12 @@ async function run(args) {
|
|
92
100
|
}
|
93
101
|
)
|
94
102
|
]);
|
95
|
-
const errors = tasksRes.filter((res) => res.status === "rejected").map((res) => res.reason).
|
103
|
+
const errors = tasksRes.filter((res) => res.status === "rejected").map((res) => res.reason).map((res) => {
|
104
|
+
if (res instanceof error.BuildError) {
|
105
|
+
return res.error;
|
106
|
+
}
|
107
|
+
return res.message;
|
108
|
+
});
|
96
109
|
if (errors.length > 0) {
|
97
110
|
return { error: true, errors };
|
98
111
|
}
|
@@ -100,6 +113,8 @@ async function run(args) {
|
|
100
113
|
exportsMap,
|
101
114
|
binsMap
|
102
115
|
});
|
116
|
+
log.lineLog();
|
117
|
+
log.log(`Build finished: ./${path.relative(sourceDir, outDir)}`);
|
103
118
|
return { error: false };
|
104
119
|
}
|
105
120
|
exports.defineViteConfig = defineViteConfig;
|
@@ -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 { buildVite } from \"./buildVite.js\";\nimport { type Args, 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\";\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 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 { viteConfig } = createViteConfig({ dirs, packageJson });\n\n return viteConfig;\n}\n\ntype RunResult =\n | {\n error: false;\n }\n | {\n error: true;\n errors: Array<string>;\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 { viteConfig, entrypoints, bins } = createViteConfig({\n dirs,\n packageJson,\n });\n\n const outputs = await buildVite({ viteConfig });\n if (outputs.error) {\n return { error: true, errors: outputs.errors };\n }\n const viteOutput = outputs.output;\n\n const exportsMap = new Map<string, ExportsObject>();\n const binsMap = new Map<string, string>();\n const tasksRes = await Promise.allSettled([\n copyStaticFilesTask(sourceDir, outDir),\n buildTypesTask({\n sourceDir,\n outDir,\n entrypoints,\n buildOutput: viteOutput,\n }).then((res) => {\n for (const [types, source] of res) {\n setExports(exportsMap, source, (entry) => {\n if (types.endsWith(\".d.ts\")) {\n entry.dcts = \"./\" + relative(outDir, types);\n }\n if (types.endsWith(\".d.mts\")) {\n entry.dmts = \"./\" + relative(outDir, types);\n }\n return entry;\n });\n }\n }),\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 const errors = tasksRes\n .filter((res) => res.status === \"rejected\")\n .map((res) => res.reason)\n .
|
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 { buildVite } from \"./buildVite.js\";\nimport { type Args, 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\";\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 modules = await detectModules(packageJson);\n const { viteConfig } = createViteConfig({ dirs, packageJson, modules });\n\n return viteConfig;\n}\n\ntype RunResult =\n | {\n error: false;\n }\n | {\n error: true;\n errors: Array<string>;\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 modules = await detectModules(packageJson);\n const { viteConfig, entrypoints, bins } = createViteConfig({\n dirs,\n packageJson,\n modules,\n });\n\n okLog(\"Vite\");\n const outputs = await buildVite({ viteConfig });\n if (outputs.error) {\n return { error: true, errors: outputs.errors };\n }\n const viteOutput = outputs.output;\n\n const exportsMap = new Map<string, ExportsObject>();\n const binsMap = new Map<string, string>();\n const tasksRes = await Promise.allSettled([\n copyStaticFilesTask(sourceDir, outDir),\n buildTypesTask({\n sourceDir,\n outDir,\n entrypoints,\n buildOutput: viteOutput,\n modules,\n }).then((res) => {\n for (const [types, source] of res) {\n setExports(exportsMap, source, (entry) => {\n if (types.endsWith(\".d.ts\")) {\n entry.dcts = \"./\" + relative(outDir, types);\n }\n if (types.endsWith(\".d.mts\")) {\n entry.dmts = \"./\" + relative(outDir, types);\n }\n return entry;\n });\n }\n }),\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 const errors = tasksRes\n .filter((res) => res.status === \"rejected\")\n .map((res) => res.reason)\n .map((res) => {\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","okLog","buildVite","copyStaticFilesTask","buildTypesTask","relative","jsFilesTask","binsTask","BuildError","writePackageJson","lineLog","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AAM,aAAa,YAAY,OAAQ,CAAA,EAAE;AAAA,MAC9D,CAAC,QAAQ;AACP,mBAAW,CAAC,OAAO,GAAG,KAAK,KAAK;AACtB,kBAAA,IAAI,KAAK,KAAK;AAAA,QACxB;AAAA,MACF;AAAA,IACF;AAAA,EAAA,CACD;AAED,QAAM,SAAS,SACZ,OAAO,CAAC,QAAQ,IAAI,WAAW,UAAU,EACzC,IAAI,CAAC,QAAQ,IAAI,MAAM,EACvB,IAAI,CAAC,QAAQ;AACZ,QAAI,eAAeC,MAAAA,YAAY;AAC7B,aAAO,IAAI;AAAA,IACb;AAEA,WAAO,IAAI;AAAA,EAAA,CACZ;AAEC,MAAA,OAAO,SAAS,GAAG;AACd,WAAA,EAAE,OAAO,MAAM;EACxB;AAEM,QAAAC,iBAAA,iBAAiB,QAAQZ,eAAa;AAAA,IAC1C;AAAA,IACA;AAAA,EAAA,CACD;AAEOa,MAAAA;AACRC,MAAA,IAAI,qBAAqBN,KAAA,SAAS,WAAW,MAAM,CAAC,EAAE;AAC/C,SAAA,EAAE,OAAO;AAClB;;;"}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
export declare function disableLog(): void;
|
2
|
+
export declare function log(...messages: Array<string>): void;
|
3
|
+
export declare function okLog(...messages: Array<string>): void;
|
4
|
+
export declare function errorLog(...messages: Array<string>): void;
|
5
|
+
export declare function lineLog(): void;
|
@@ -0,0 +1,26 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
+
let logEnabled = true;
|
4
|
+
function disableLog() {
|
5
|
+
logEnabled = false;
|
6
|
+
}
|
7
|
+
function log(...messages) {
|
8
|
+
if (logEnabled) {
|
9
|
+
console.log(...messages);
|
10
|
+
}
|
11
|
+
}
|
12
|
+
function okLog(...messages) {
|
13
|
+
log(`✅ ${messages.join(" ")}`);
|
14
|
+
}
|
15
|
+
function errorLog(...messages) {
|
16
|
+
log(`❌ ${messages.join(" ")}`);
|
17
|
+
}
|
18
|
+
function lineLog() {
|
19
|
+
log("=".repeat(40));
|
20
|
+
}
|
21
|
+
exports.disableLog = disableLog;
|
22
|
+
exports.errorLog = errorLog;
|
23
|
+
exports.lineLog = lineLog;
|
24
|
+
exports.log = log;
|
25
|
+
exports.okLog = okLog;
|
26
|
+
//# sourceMappingURL=log.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"log.js","sources":["../../../../src/log.ts"],"sourcesContent":["let logEnabled = true;\nexport function disableLog() {\n logEnabled = false;\n}\n\nexport function log(...messages: Array<string>) {\n if (logEnabled) {\n console.log(...messages);\n }\n}\n\nexport function okLog(...messages: Array<string>) {\n log(`✅ ${messages.join(\" \")}`);\n}\nexport function errorLog(...messages: Array<string>) {\n log(`❌ ${messages.join(\" \")}`);\n}\nexport function lineLog() {\n log(\"=\".repeat(40));\n}\n"],"names":[],"mappings":";;AAAA,IAAI,aAAa;AACV,SAAS,aAAa;AACd,eAAA;AACf;AAEO,SAAS,OAAO,UAAyB;AAC9C,MAAI,YAAY;AACN,YAAA,IAAI,GAAG,QAAQ;AAAA,EACzB;AACF;AAEO,SAAS,SAAS,UAAyB;AAChD,MAAI,KAAK,SAAS,KAAK,GAAG,CAAC,EAAE;AAC/B;AACO,SAAS,YAAY,UAAyB;AACnD,MAAI,KAAK,SAAS,KAAK,GAAG,CAAC,EAAE;AAC/B;AACO,SAAS,UAAU;AACpB,MAAA,IAAI,OAAO,EAAE,CAAC;AACpB;;;;;;"}
|
@@ -1,9 +1,11 @@
|
|
1
|
-
import {
|
1
|
+
import type { Plugin } from "vite";
|
2
2
|
import { type PackageJson } from "../../packageJson.js";
|
3
3
|
import { type Dirs } from "../../resolveDirs.js";
|
4
|
+
import { type DetectedModules } from "../../detectModules.js";
|
4
5
|
type BabelPluginOptions = {
|
5
6
|
packageJson: PackageJson;
|
6
7
|
dirs: Dirs;
|
8
|
+
modules: DetectedModules;
|
7
9
|
};
|
8
|
-
export declare function babelPlugin({ packageJson, dirs }: BabelPluginOptions): Plugin;
|
10
|
+
export declare function babelPlugin({ packageJson, dirs, modules, }: BabelPluginOptions): Plugin;
|
9
11
|
export {};
|
@@ -1,32 +1,11 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __create = Object.create;
|
3
|
-
var __defProp = Object.defineProperty;
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
10
|
-
for (let key of __getOwnPropNames(from))
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
12
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
13
|
-
}
|
14
|
-
return to;
|
15
|
-
};
|
16
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
17
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
18
|
-
// file that has been converted to a CommonJS file using a Babel-
|
19
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
20
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
22
|
-
mod
|
23
|
-
));
|
24
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
25
|
-
require("vite");
|
26
3
|
const path = require("node:path");
|
27
4
|
const findBabelConfig = require("./findBabelConfig.js");
|
28
5
|
require("node:fs/promises");
|
29
6
|
require("zod");
|
7
|
+
require("semver");
|
8
|
+
const log = require("../../log.js");
|
30
9
|
function _interopNamespaceDefault(e) {
|
31
10
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
32
11
|
if (e) {
|
@@ -44,25 +23,21 @@ function _interopNamespaceDefault(e) {
|
|
44
23
|
return Object.freeze(n);
|
45
24
|
}
|
46
25
|
const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
|
47
|
-
function babelPlugin({
|
48
|
-
|
26
|
+
function babelPlugin({
|
27
|
+
packageJson,
|
28
|
+
dirs,
|
29
|
+
modules
|
30
|
+
}) {
|
49
31
|
let hasBabelConfig = false;
|
50
32
|
return {
|
51
33
|
name: "smartbundle:babel",
|
52
34
|
async buildStart() {
|
53
|
-
try {
|
54
|
-
if (!("@babel/core" in (packageJson.optionalDependencies ?? {}))) {
|
55
|
-
babelCore = await import("@babel/core");
|
56
|
-
}
|
57
|
-
} catch (e) {
|
58
|
-
console.error(e);
|
59
|
-
}
|
60
35
|
hasBabelConfig = await findBabelConfig.findBabelConfig(dirs.sourceDir, packageJson);
|
61
|
-
if (
|
36
|
+
if (modules.babel && !hasBabelConfig) {
|
62
37
|
this.warn(
|
63
38
|
"We have found a @babel/core package, but config was not found. It could be a bug"
|
64
39
|
);
|
65
|
-
} else if (!
|
40
|
+
} else if (!modules.babel && hasBabelConfig) {
|
66
41
|
this.error(
|
67
42
|
new Error(
|
68
43
|
"We have found a babel config. Please install @babel/core to devDeps or remove the config file"
|
@@ -71,7 +46,7 @@ function babelPlugin({ packageJson, dirs }) {
|
|
71
46
|
}
|
72
47
|
},
|
73
48
|
async transform(code, id) {
|
74
|
-
if (!
|
49
|
+
if (!modules.babel || !hasBabelConfig) {
|
75
50
|
return null;
|
76
51
|
}
|
77
52
|
const extname = path__namespace.extname(id);
|
@@ -79,7 +54,7 @@ function babelPlugin({ packageJson, dirs }) {
|
|
79
54
|
return null;
|
80
55
|
}
|
81
56
|
const map = this.getCombinedSourcemap();
|
82
|
-
const result = await
|
57
|
+
const result = await modules.babel.transformAsync(code, {
|
83
58
|
filename: id,
|
84
59
|
sourceMaps: true,
|
85
60
|
inputSourceMap: map
|
@@ -91,6 +66,15 @@ function babelPlugin({ packageJson, dirs }) {
|
|
91
66
|
code: result.code,
|
92
67
|
map: result.map
|
93
68
|
};
|
69
|
+
},
|
70
|
+
buildEnd(error) {
|
71
|
+
if (!error) {
|
72
|
+
if (modules.babel && hasBabelConfig) {
|
73
|
+
log.okLog("Babel");
|
74
|
+
}
|
75
|
+
} else {
|
76
|
+
this.error(error);
|
77
|
+
}
|
94
78
|
}
|
95
79
|
};
|
96
80
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../../src/plugins/babel/index.ts"],"sourcesContent":["import {
|
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 (!error) {\n if (modules.babel && hasBabelConfig) {\n okLog(\"Babel\");\n }\n } else {\n this.error(error);\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,QAAA;AAAA,MAEO,WAAA,CAAC,QAAQ,SAAS,gBAAgB;AACtC,aAAA;AAAA,UACH,IAAI;AAAA,YACF;AAAA,UACF;AAAA,QAAA;AAAA,MAEJ;AAAA,IACF;AAAA,IACA,MAAM,UAAU,MAAM,IAAI;AACxB,UAAI,CAAC,QAAQ,SAAS,CAAC,gBAAgB;AAC9B,eAAA;AAAA,MACT;AAEM,YAAA,UAAUC,gBAAK,QAAQ,EAAE;AAC/B,UAAI,CAAC,CAAC,OAAO,KAAK,EAAE,SAAS,OAAO,GAAG;AAC9B,eAAA;AAAA,MACT;AAEM,YAAA,MAAM,KAAK;AAEjB,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,MAC/C;AAEO,aAAA;AAAA,QACL,MAAM,OAAO;AAAA,QACb,KAAK,OAAO;AAAA,MAAA;AAAA,IAEhB;AAAA,IACA,SAAS,OAAO;AACd,UAAI,CAAC,OAAO;AACN,YAAA,QAAQ,SAAS,gBAAgB;AACnCC,cAAA,MAAM,OAAO;AAAA,QACf;AAAA,MAAA,OACK;AACL,aAAK,MAAM,KAAK;AAAA,MAClB;AAAA,IACF;AAAA,EAAA;AAEJ;;"}
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import {
|
2
|
-
import type
|
1
|
+
import type { Plugin } from "vite";
|
2
|
+
import { type DetectedModules } from "../../detectModules.js";
|
3
3
|
type ReactPluginArg = {
|
4
|
-
|
4
|
+
modules: DetectedModules;
|
5
5
|
};
|
6
|
-
export declare function reactPlugin({
|
6
|
+
export declare function reactPlugin({ modules }: ReactPluginArg): Plugin;
|
7
7
|
export {};
|
@@ -1,13 +1,15 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
3
|
const vite = require("vite");
|
4
|
-
|
4
|
+
require("node:fs/promises");
|
5
|
+
require("zod");
|
6
|
+
require("node:path");
|
7
|
+
require("semver");
|
8
|
+
const log = require("../../log.js");
|
5
9
|
const errorJsxMessage = "SmartBundle cannot find the react dependency inside dependencies, optionalDependencies or peerDependencies. Please, install it before bundling";
|
6
|
-
function reactPlugin({
|
7
|
-
var _a, _b, _c;
|
10
|
+
function reactPlugin({ modules }) {
|
8
11
|
const pluginName = "smartbundle:react";
|
9
|
-
|
10
|
-
if (!reactVersion) {
|
12
|
+
if (modules.react == null) {
|
11
13
|
return {
|
12
14
|
name: pluginName,
|
13
15
|
transform(code, id) {
|
@@ -25,10 +27,6 @@ function reactPlugin({ packageJson }) {
|
|
25
27
|
}
|
26
28
|
};
|
27
29
|
}
|
28
|
-
const isLegacyTransform = semver.lt(
|
29
|
-
semver.minVersion(reactVersion),
|
30
|
-
"17.0.0"
|
31
|
-
);
|
32
30
|
return {
|
33
31
|
name: pluginName,
|
34
32
|
enforce: "pre",
|
@@ -44,11 +42,18 @@ function reactPlugin({ packageJson }) {
|
|
44
42
|
id,
|
45
43
|
{
|
46
44
|
loader: isJs || isJsx ? "jsx" : "tsx",
|
47
|
-
jsx:
|
45
|
+
jsx: modules.react === "legacy" ? "transform" : "automatic",
|
48
46
|
sourcemap: true
|
49
47
|
},
|
50
48
|
this.getCombinedSourcemap()
|
51
49
|
);
|
50
|
+
},
|
51
|
+
buildEnd(err) {
|
52
|
+
if (!err) {
|
53
|
+
log.okLog("React");
|
54
|
+
} else {
|
55
|
+
this.error(err);
|
56
|
+
}
|
52
57
|
}
|
53
58
|
};
|
54
59
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../../src/plugins/react/index.ts"],"sourcesContent":["import {
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../../src/plugins/react/index.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\nimport { transformWithEsbuild } from \"vite\";\nimport { type DetectedModules } from \"../../detectModules.js\";\nimport { okLog } from \"../../log.js\";\n\ntype ReactPluginArg = {\n modules: DetectedModules;\n};\n\nconst errorJsxMessage =\n \"SmartBundle cannot find the react dependency inside dependencies, optionalDependencies or peerDependencies. Please, install it before bundling\";\n\nexport function reactPlugin({ modules }: ReactPluginArg): Plugin {\n const pluginName = \"smartbundle:react\";\n\n if (modules.react == null) {\n return {\n name: pluginName,\n transform(code, id) {\n if (id.endsWith(\".jsx\") || id.endsWith(\".tsx\")) {\n this.error(new Error(errorJsxMessage));\n }\n },\n buildEnd(err) {\n if (err) {\n const isJsxError = err.message.includes(\"JSX\");\n if (isJsxError) {\n this.error(new Error(errorJsxMessage));\n }\n }\n },\n };\n }\n\n return {\n name: pluginName,\n enforce: \"pre\",\n async transform(code, id) {\n const isJs = id.endsWith(\".js\");\n const isJsx = id.endsWith(\".jsx\");\n const isTsx = id.endsWith(\".tsx\");\n if (!(isJs || isJsx || isTsx)) {\n return null;\n }\n\n return await transformWithEsbuild(\n code,\n id,\n {\n loader: isJs || isJsx ? \"jsx\" : \"tsx\",\n jsx: modules.react === \"legacy\" ? \"transform\" : \"automatic\",\n sourcemap: true,\n },\n this.getCombinedSourcemap(),\n );\n },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
@@ -2,8 +2,8 @@
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
3
|
const fs = require("node:fs/promises");
|
4
4
|
const path = require("node:path");
|
5
|
-
require("vite");
|
6
5
|
const utils = require("./utils.js");
|
6
|
+
const log = require("../log.js");
|
7
7
|
async function binsTask({
|
8
8
|
buildOutput,
|
9
9
|
bins,
|
@@ -39,6 +39,9 @@ import("${totalPath}");
|
|
39
39
|
res.set(path.relative(outDir, execPath), binName);
|
40
40
|
}
|
41
41
|
}
|
42
|
+
if (res.size) {
|
43
|
+
log.okLog("Bin:", [...res.values()].join(", "));
|
44
|
+
}
|
42
45
|
return res;
|
43
46
|
}
|
44
47
|
exports.binsTask = binsTask;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"binsTask.js","sources":["../../../../../src/tasks/binsTask.ts"],"sourcesContent":["import { mkdir, writeFile } from \"node:fs/promises\";\nimport { join, relative } from \"node:path\";\nimport {
|
1
|
+
{"version":3,"file":"binsTask.js","sources":["../../../../../src/tasks/binsTask.ts"],"sourcesContent":["import { mkdir, writeFile } from \"node:fs/promises\";\nimport { join, relative } from \"node:path\";\nimport type { Rollup } from \"vite\";\nimport { reverseMap } from \"./utils.js\";\nimport { okLog } from \"../log.js\";\n\ntype BinsTaskOption = {\n buildOutput: Rollup.OutputChunk[];\n bins: Map<string, string>;\n outBinsDir: string;\n outDir: string;\n};\n\nexport async function binsTask({\n buildOutput,\n bins,\n outBinsDir,\n outDir,\n}: BinsTaskOption) {\n if (bins.size === 0) {\n return new Map<string, string>();\n }\n await mkdir(outBinsDir, { recursive: true });\n const reversedEntrypoints = reverseMap(bins);\n const res = new Map<string, string>();\n for (const el of buildOutput) {\n if (el.facadeModuleId == null) {\n continue;\n }\n if (el.fileName.endsWith(\".js\")) {\n continue;\n }\n const binsNames = reversedEntrypoints.get(el.facadeModuleId);\n if (!binsNames) {\n continue;\n }\n for (const binName of binsNames) {\n const totalPath = relative(outBinsDir, join(outDir, el.fileName));\n const execPath = join(outBinsDir, `${binName}.js`);\n await writeFile(\n execPath,\n `#!/usr/bin/env node\nimport(\"${totalPath}\");\n`,\n );\n res.set(relative(outDir, execPath), binName);\n }\n }\n\n if (res.size) {\n okLog(\"Bin:\", [...res.values()].join(\", \"));\n }\n\n return res;\n}\n"],"names":["mkdir","reverseMap","relative","join","writeFile","okLog"],"mappings":";;;;;;AAaA,eAAsB,SAAS;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAmB;AACb,MAAA,KAAK,SAAS,GAAG;AACnB,+BAAW,IAAoB;AAAA,EACjC;AACA,QAAMA,GAAM,MAAA,YAAY,EAAE,WAAW,KAAM,CAAA;AACrC,QAAA,sBAAsBC,iBAAW,IAAI;AACrC,QAAA,0BAAU;AAChB,aAAW,MAAM,aAAa;AACxB,QAAA,GAAG,kBAAkB,MAAM;AAC7B;AAAA,IACF;AACA,QAAI,GAAG,SAAS,SAAS,KAAK,GAAG;AAC/B;AAAA,IACF;AACA,UAAM,YAAY,oBAAoB,IAAI,GAAG,cAAc;AAC3D,QAAI,CAAC,WAAW;AACd;AAAA,IACF;AACA,eAAW,WAAW,WAAW;AAC/B,YAAM,YAAYC,KAAS,SAAA,YAAYC,KAAAA,KAAK,QAAQ,GAAG,QAAQ,CAAC;AAChE,YAAM,WAAWA,KAAAA,KAAK,YAAY,GAAG,OAAO,KAAK;AAC3C,YAAAC,GAAA;AAAA,QACJ;AAAA,QACA;AAAA,UACE,SAAS;AAAA;AAAA,MAAA;AAGb,UAAI,IAAIF,KAAA,SAAS,QAAQ,QAAQ,GAAG,OAAO;AAAA,IAC7C;AAAA,EACF;AAEA,MAAI,IAAI,MAAM;AACNG,cAAA,QAAQ,CAAC,GAAG,IAAI,QAAQ,EAAE,KAAK,IAAI,CAAC;AAAA,EAC5C;AAEO,SAAA;AACT;;"}
|
@@ -1,9 +1,11 @@
|
|
1
1
|
import { type Rollup } from "vite";
|
2
|
+
import type { DetectedModules } from "../../detectModules.js";
|
2
3
|
type BuildTypesTaskOption = {
|
3
4
|
buildOutput: Rollup.OutputChunk[];
|
4
5
|
entrypoints: Map<string, string>;
|
5
6
|
sourceDir: string;
|
6
7
|
outDir: string;
|
8
|
+
modules: DetectedModules;
|
7
9
|
};
|
8
|
-
export declare function buildTypesTask({ buildOutput, entrypoints, sourceDir, outDir, }: BuildTypesTaskOption): Promise<Map<string, string>>;
|
10
|
+
export declare function buildTypesTask({ buildOutput, entrypoints, sourceDir, outDir, modules, }: BuildTypesTaskOption): Promise<Map<string, string>>;
|
9
11
|
export {};
|