smartbundle 0.12.2 → 0.12.4
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/detectModules.d.ts +14 -2
- package/__compiled__/cjs/src/detectModules.js +58 -9
- package/__compiled__/cjs/src/detectModules.js.map +1 -1
- package/__compiled__/cjs/src/index.d.ts +4 -1
- package/__compiled__/cjs/src/index.js +10 -2
- package/__compiled__/cjs/src/index.js.map +1 -1
- package/__compiled__/cjs/src/tasks/buildTypesTask/callTypescript.d.ts +2 -1
- package/__compiled__/cjs/src/tasks/buildTypesTask/callTypescript.js +5 -33
- package/__compiled__/cjs/src/tasks/buildTypesTask/callTypescript.js.map +1 -1
- package/__compiled__/cjs/src/tasks/copyStaticFilesTask.js +5 -3
- package/__compiled__/cjs/src/tasks/copyStaticFilesTask.js.map +1 -1
- package/__compiled__/esm/src/detectModules.d.mts +14 -2
- package/__compiled__/esm/src/detectModules.mjs +59 -10
- package/__compiled__/esm/src/detectModules.mjs.map +1 -1
- package/__compiled__/esm/src/index.d.mts +4 -1
- package/__compiled__/esm/src/index.mjs +10 -2
- package/__compiled__/esm/src/index.mjs.map +1 -1
- package/__compiled__/esm/src/tasks/buildTypesTask/callTypescript.d.mts +2 -1
- package/__compiled__/esm/src/tasks/buildTypesTask/callTypescript.mjs +5 -33
- package/__compiled__/esm/src/tasks/buildTypesTask/callTypescript.mjs.map +1 -1
- package/__compiled__/esm/src/tasks/copyStaticFilesTask.mjs +5 -3
- package/__compiled__/esm/src/tasks/copyStaticFilesTask.mjs.map +1 -1
- package/package.json +1 -1
@@ -1,11 +1,23 @@
|
|
1
1
|
import { type PackageJson } from "./packageJson.js";
|
2
2
|
import semver from "semver";
|
3
|
+
import type { Dirs } from "./resolveDirs.js";
|
4
|
+
export type TS = {
|
5
|
+
ts: typeof import("typescript");
|
6
|
+
parsedConfig: import("typescript").ParsedCommandLine;
|
7
|
+
host: import("typescript").CompilerHost;
|
8
|
+
};
|
3
9
|
export type DetectedModules = {
|
4
|
-
ts?:
|
10
|
+
ts?: TS;
|
5
11
|
babel?: typeof import("@babel/core");
|
6
12
|
react?: "legacy" | "modern";
|
7
13
|
};
|
8
14
|
type DepType = "dependencies" | "devDependencies" | "peerDependencies" | "optionalDependencies";
|
9
15
|
export declare function getMinVersion(packageJson: PackageJson, depName: string, exclude: DepType[]): semver.SemVer | null;
|
10
|
-
export declare function detectModules(packageJson: PackageJson): Promise<
|
16
|
+
export declare function detectModules(packageJson: PackageJson, dirs: Dirs): Promise<{
|
17
|
+
error: false;
|
18
|
+
modules: DetectedModules;
|
19
|
+
} | {
|
20
|
+
error: true;
|
21
|
+
errors: Array<string>;
|
22
|
+
}>;
|
11
23
|
export {};
|
@@ -84,19 +84,68 @@ async function detectReact(packageJson) {
|
|
84
84
|
}
|
85
85
|
log.errorLog("react");
|
86
86
|
}
|
87
|
-
async function
|
88
|
-
|
89
|
-
log.log("Detecting modules");
|
87
|
+
async function detectTypescript(dirs) {
|
88
|
+
let ts;
|
90
89
|
try {
|
91
|
-
|
92
|
-
log.okLog("typescript, version:", result.ts.version);
|
90
|
+
ts = (await import("typescript")).default;
|
93
91
|
} catch {
|
94
92
|
log.errorLog("typescript");
|
93
|
+
return;
|
94
|
+
}
|
95
|
+
log.okLog("typescript, version:", ts.version);
|
96
|
+
const configFilePath = ts.findConfigFile(dirs.sourceDir, ts.sys.fileExists);
|
97
|
+
if (!configFilePath) {
|
98
|
+
throw new Error(
|
99
|
+
"Cannot find a tsconfig.json file. You should declare it. Please, read the https://github.com/XaveScor/smartbundle/issues/131 for more information"
|
100
|
+
);
|
101
|
+
}
|
102
|
+
const configFile = ts.readConfigFile(configFilePath, ts.sys.readFile);
|
103
|
+
if (configFile.error) {
|
104
|
+
const readableError = ts.flattenDiagnosticMessageText(
|
105
|
+
configFile.error.messageText,
|
106
|
+
"\n"
|
107
|
+
);
|
108
|
+
throw new Error(`Cannot read tsconfig.json file, error: ${readableError}`);
|
109
|
+
}
|
110
|
+
const parsedConfig = ts.parseJsonConfigFileContent(
|
111
|
+
configFile.config,
|
112
|
+
ts.sys,
|
113
|
+
dirs.sourceDir,
|
114
|
+
{
|
115
|
+
declaration: true,
|
116
|
+
emitDeclarationOnly: true,
|
117
|
+
strict: false,
|
118
|
+
strictNullChecks: false,
|
119
|
+
strictFunctionTypes: false,
|
120
|
+
strictPropertyInitialization: false,
|
121
|
+
skipLibCheck: true,
|
122
|
+
skipDefaultLibCheck: true,
|
123
|
+
outDir: "",
|
124
|
+
// https://github.com/XaveScor/bobrik/issues/22#issuecomment-2308552352
|
125
|
+
noEmit: false
|
126
|
+
},
|
127
|
+
configFilePath
|
128
|
+
);
|
129
|
+
if (!parsedConfig.options.verbatimModuleSyntax) {
|
130
|
+
throw new Error(
|
131
|
+
"verbatimModuleSyntax should be enabled in tsconfig.json. Read https://github.com/XaveScor/smartbundle/issues/131 for more explanation.\nYou also can upvote the issue if you need the support of verbatimModuleSyntax: false in your library"
|
132
|
+
);
|
133
|
+
}
|
134
|
+
const host = ts.createCompilerHost(parsedConfig.options);
|
135
|
+
return { ts, parsedConfig, host };
|
136
|
+
}
|
137
|
+
async function detectModules(packageJson, dirs) {
|
138
|
+
try {
|
139
|
+
const result = {};
|
140
|
+
log.log("Detecting modules");
|
141
|
+
result.ts = await detectTypescript(dirs);
|
142
|
+
result.babel = await detectBabel(packageJson);
|
143
|
+
result.react = await detectReact(packageJson);
|
144
|
+
log.lineLog();
|
145
|
+
return { error: false, modules: result };
|
146
|
+
} catch (e) {
|
147
|
+
return { error: true, errors: [e.message] };
|
95
148
|
}
|
96
|
-
result.babel = await detectBabel(packageJson);
|
97
|
-
result.react = await detectReact(packageJson);
|
98
|
-
log.lineLog();
|
99
|
-
return result;
|
100
149
|
}
|
101
150
|
exports.detectModules = detectModules;
|
102
151
|
exports.getMinVersion = getMinVersion;
|
@@ -1 +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, warnLog } from \"./log.js\";\n\nexport type
|
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, warnLog } from \"./log.js\";\nimport type { Dirs } from \"./resolveDirs.js\";\n\nexport type TS = {\n ts: typeof import(\"typescript\");\n parsedConfig: import(\"typescript\").ParsedCommandLine;\n host: import(\"typescript\").CompilerHost;\n};\nexport type DetectedModules = {\n ts?: TS;\n babel?: typeof import(\"@babel/core\");\n react?: \"legacy\" | \"modern\";\n};\n\ntype DepType =\n | \"dependencies\"\n | \"devDependencies\"\n | \"peerDependencies\"\n | \"optionalDependencies\";\nexport function getMinVersion(\n packageJson: PackageJson,\n depName: string,\n exclude: DepType[],\n): semver.SemVer | null {\n const allDepKeys = new Set<DepType>([\n \"dependencies\",\n \"devDependencies\",\n \"peerDependencies\",\n \"optionalDependencies\",\n ]);\n for (const e of exclude) {\n allDepKeys.delete(e);\n }\n\n let minVersion: semver.SemVer | null = null;\n for (const depKey of allDepKeys) {\n const depVersion = packageJson[depKey]?.[depName];\n if (depVersion) {\n const version = semver.minVersion(depVersion);\n if (!version) {\n warnLog(\"node-semver cannot parse version of\", depName, \"from\", depKey);\n warnLog(\"Version:\", depVersion);\n continue;\n }\n if (!minVersion) {\n minVersion = version;\n continue;\n }\n if (semver.lt(version, minVersion)) {\n minVersion = version;\n }\n }\n }\n\n return minVersion;\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 = getMinVersion(packageJson, \"react\", [\"devDependencies\"]);\n if (reactVersion) {\n const isLegacy = semver.lt(reactVersion, \"17.0.0\");\n const transform = isLegacy ? \"legacy\" : \"modern\";\n okLog(\n `react, min version: ${reactVersion.version}. Transform: ${transform}`,\n );\n return transform;\n }\n errorLog(\"react\");\n}\n\nasync function detectTypescript(dirs: Dirs): Promise<TS | undefined> {\n let ts: typeof import(\"typescript\");\n try {\n // ts <=4.3 has no named exports. The all methods is located in the default export\n ts = (await import(\"typescript\")).default;\n } catch {\n errorLog(\"typescript\");\n return;\n }\n\n okLog(\"typescript, version:\", ts.version);\n\n const configFilePath = ts.findConfigFile(dirs.sourceDir, ts.sys.fileExists);\n if (!configFilePath) {\n throw new Error(\n \"Cannot find a tsconfig.json file. You should declare it. Please, read the https://github.com/XaveScor/smartbundle/issues/131 for more information\",\n );\n }\n const configFile = ts.readConfigFile(configFilePath, ts.sys.readFile);\n if (configFile.error) {\n const readableError = ts.flattenDiagnosticMessageText(\n configFile.error.messageText,\n \"\\n\",\n );\n throw new Error(`Cannot read tsconfig.json file, error: ${readableError}`);\n }\n const parsedConfig = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n dirs.sourceDir,\n {\n declaration: true,\n emitDeclarationOnly: true,\n strict: false,\n strictNullChecks: false,\n strictFunctionTypes: false,\n strictPropertyInitialization: false,\n skipLibCheck: true,\n skipDefaultLibCheck: true,\n outDir: \"\",\n // https://github.com/XaveScor/bobrik/issues/22#issuecomment-2308552352\n noEmit: false,\n },\n configFilePath,\n );\n\n if (!parsedConfig.options.verbatimModuleSyntax) {\n throw new Error(\n \"verbatimModuleSyntax should be enabled in tsconfig.json. Read https://github.com/XaveScor/smartbundle/issues/131 for more explanation.\\n\" +\n \"You also can upvote the issue if you need the support of verbatimModuleSyntax: false in your library\",\n );\n }\n\n const host = ts.createCompilerHost(parsedConfig.options);\n\n return { ts, parsedConfig, host };\n}\n\nexport async function detectModules(\n packageJson: PackageJson,\n dirs: Dirs,\n): Promise<\n | { error: false; modules: DetectedModules }\n | { error: true; errors: Array<string> }\n> {\n try {\n const result: DetectedModules = {};\n log(\"Detecting modules\");\n\n result.ts = await detectTypescript(dirs);\n result.babel = await detectBabel(packageJson);\n result.react = await detectReact(packageJson);\n\n lineLog();\n return { error: false, modules: result };\n } catch (e: any) {\n return { error: true, errors: [e.message] };\n }\n}\n"],"names":["warnLog","errorLog","okLog","log","lineLog"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBgB,SAAA,cACd,aACA,SACA,SACsB;;AAChB,QAAA,iCAAiB,IAAa;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AACD,aAAW,KAAK,SAAS;AACvB,eAAW,OAAO,CAAC;AAAA,EAAA;AAGrB,MAAI,aAAmC;AACvC,aAAW,UAAU,YAAY;AAC/B,UAAM,cAAa,iBAAY,MAAM,MAAlB,mBAAsB;AACzC,QAAI,YAAY;AACR,YAAA,UAAU,OAAO,WAAW,UAAU;AAC5C,UAAI,CAAC,SAAS;AACJA,YAAAA,QAAA,uCAAuC,SAAS,QAAQ,MAAM;AACtEA,YAAA,QAAQ,YAAY,UAAU;AAC9B;AAAA,MAAA;AAEF,UAAI,CAAC,YAAY;AACF,qBAAA;AACb;AAAA,MAAA;AAEF,UAAI,OAAO,GAAG,SAAS,UAAU,GAAG;AACrB,qBAAA;AAAA,MAAA;AAAA,IACf;AAAA,EACF;AAGK,SAAA;AACT;AAEA,eAAe,YACb,aACmD;AACnD,MAAI,kBAAkB,YAAY,wBAAwB,CAAK,IAAA;AAC7DC,QAAAA,SAAS,oDAAoD;AAC7D;AAAA,EAAA;AAGE,MAAA;AACI,UAAA,QAAQ,MAAM,OAAO,aAAa;AAClCC,cAAA,mBAAmB,MAAM,OAAO;AAC/B,WAAA;AAAA,EAAA,QACD;AACND,QAAAA,SA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AAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EAAA;AAGF,QAAM,OAAO,GAAG,mBAAmB,aAAa,OAAO;AAEhD,SAAA,EAAE,IAAI,cAAc,KAAK;AAClC;AAEsB,eAAA,cACpB,aACA,MAIA;AACI,MAAA;AACF,UAAM,SAA0B,CAAC;AACjCC,QAAAA,IAAI,mBAAmB;AAEhB,WAAA,KAAK,MAAM,iBAAiB,IAAI;AAChC,WAAA,QAAQ,MAAM,YAAY,WAAW;AACrC,WAAA,QAAQ,MAAM,YAAY,WAAW;AAEpCC,gBAAA;AACR,WAAO,EAAE,OAAO,OAAO,SAAS,OAAO;AAAA,WAChC,GAAQ;AACf,WAAO,EAAE,OAAO,MAAM,QAAQ,CAAC,EAAE,OAAO,EAAE;AAAA,EAAA;AAE9C;;;"}
|
@@ -1,5 +1,8 @@
|
|
1
1
|
import { type Args } from "./args.js";
|
2
|
-
export declare function defineViteConfig(args?: Args): Promise<import("vite").UserConfig
|
2
|
+
export declare function defineViteConfig(args?: Args): Promise<import("vite").UserConfig | {
|
3
|
+
error: boolean;
|
4
|
+
errors: string[];
|
5
|
+
}>;
|
3
6
|
type RunResult = {
|
4
7
|
error: false;
|
5
8
|
} | {
|
@@ -32,7 +32,11 @@ async function defineViteConfig(args = {}) {
|
|
32
32
|
console.error(packageJson$1);
|
33
33
|
throw new Error("Failed to parse package.json");
|
34
34
|
}
|
35
|
-
const
|
35
|
+
const modulesResult = await detectModules.detectModules(packageJson$1, dirs);
|
36
|
+
if (modulesResult.error) {
|
37
|
+
return { error: true, errors: modulesResult.errors };
|
38
|
+
}
|
39
|
+
const { modules } = modulesResult;
|
36
40
|
const { viteConfig } = createViteConfig.createViteConfig({ dirs, packageJson: packageJson$1, modules });
|
37
41
|
return viteConfig;
|
38
42
|
}
|
@@ -45,7 +49,11 @@ async function run(args) {
|
|
45
49
|
if (Array.isArray(packageJson$1)) {
|
46
50
|
return { error: true, errors: packageJson$1 };
|
47
51
|
}
|
48
|
-
const
|
52
|
+
const modulesResult = await detectModules.detectModules(packageJson$1, dirs);
|
53
|
+
if (modulesResult.error) {
|
54
|
+
return { error: true, errors: modulesResult.errors };
|
55
|
+
}
|
56
|
+
const { modules } = modulesResult;
|
49
57
|
const { viteConfig, entrypoints, bins } = createViteConfig.createViteConfig({
|
50
58
|
dirs,
|
51
59
|
packageJson: packageJson$1,
|
@@ -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
|
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({ 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 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 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","BuildError","writePackageJson","lineLog","log"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,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,iBAAA;AACL,QAAA,OAAOC,wBAAY,IAAI;AAC7B,QAAM,EAAE,WAAW,QAAQ,YAAgB,IAAA;AAE3C,QAAMC,GAAAA,GAAG,QAAQ,EAAE,WAAW,MAAM,OAAO,MAAM;AACjD,QAAMC,GAAM,MAAA,QAAQ,EAAE,WAAW,MAAM;AACvC,QAAMC,gBAAc,MAAMC,YAAAA,iBAAiB,EAAE,WAAW,aAAa;AAEjE,MAAA,MAAM,QAAQD,aAAW,GAAG;AAC9B,YAAQ,MAAMA,aAAW;AACnB,UAAA,IAAI,MAAM,8BAA8B;AAAA,EAAA;AAGhD,QAAM,gBAAgB,MAAME,4BAAcF,eAAa,IAAI;AAC3D,MAAI,cAAc,OAAO;AACvB,WAAO,EAAE,OAAO,MAAM,QAAQ,cAAc,OAAO;AAAA,EAAA;AAE/C,QAAA,EAAE,YAAY;AACd,QAAA,EAAE,eAAeG,iBAAA,iBAAiB,EAAE,MAAMH,aAAAA,eAAa,SAAS;AAE/D,SAAA;AACT;AAWA,eAAsB,IAAI,MAAgC;AAClD,QAAA,OAAOH,wBAAY,IAAI;AAC7B,QAAM,EAAE,WAA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son } from "../../packageJson.js";
|
2
|
+
import { type TS } from "../../detectModules.js";
|
2
3
|
import { type Dirs } from "../../resolveDirs.js";
|
3
4
|
type BuildTypesOptions = {
|
4
|
-
ts:
|
5
|
+
ts: TS;
|
5
6
|
dirs: Dirs;
|
6
7
|
packageJson: PackageJson;
|
7
8
|
tsEntrypoints: string[];
|
@@ -41,40 +41,12 @@ async function callTypescript({
|
|
41
41
|
packageJson
|
42
42
|
}) {
|
43
43
|
const { sourceDir, outDir, esmOutDir, cjsOutDir } = dirs;
|
44
|
-
const configPath = path__namespace.join(sourceDir, "tsconfig.json");
|
45
|
-
const configFile = ts.readConfigFile(
|
46
|
-
configPath,
|
47
|
-
(path2) => (
|
48
|
-
// https://github.com/XaveScor/bobrik/issues/22
|
49
|
-
fs__namespace.readFileSync(path2, "utf-8")
|
50
|
-
)
|
51
|
-
);
|
52
|
-
const parsedCommandLine = ts.parseJsonConfigFileContent(
|
53
|
-
configFile.config,
|
54
|
-
ts.sys,
|
55
|
-
sourceDir,
|
56
|
-
{
|
57
|
-
declaration: true,
|
58
|
-
emitDeclarationOnly: true,
|
59
|
-
strict: false,
|
60
|
-
strictNullChecks: false,
|
61
|
-
strictFunctionTypes: false,
|
62
|
-
strictPropertyInitialization: false,
|
63
|
-
skipLibCheck: true,
|
64
|
-
skipDefaultLibCheck: true,
|
65
|
-
outDir: "",
|
66
|
-
// https://github.com/XaveScor/bobrik/issues/22#issuecomment-2308552352
|
67
|
-
noEmit: false
|
68
|
-
},
|
69
|
-
configPath
|
70
|
-
);
|
71
|
-
const host = ts.createCompilerHost(parsedCommandLine.options);
|
72
44
|
const sourceToCjsDtsMap = /* @__PURE__ */ new Map();
|
73
45
|
const sourceToEsmDtsMap = /* @__PURE__ */ new Map();
|
74
|
-
const program = ts.createProgram(
|
46
|
+
const program = ts.ts.createProgram(
|
75
47
|
tsEntrypoints,
|
76
|
-
|
77
|
-
host
|
48
|
+
ts.parsedConfig.options,
|
49
|
+
ts.host
|
78
50
|
);
|
79
51
|
program.emit(void 0, (fileName, data) => {
|
80
52
|
const relativePath = path__namespace.relative(sourceDir, fileName);
|
@@ -98,7 +70,7 @@ async function callTypescript({
|
|
98
70
|
const relativePath = path__namespace.relative(outDir, file);
|
99
71
|
if (file.endsWith(".d.ts")) {
|
100
72
|
const transformedCode = inlineExtensions.inlineExtensionsCjs(
|
101
|
-
ts,
|
73
|
+
ts.ts,
|
102
74
|
content,
|
103
75
|
makeFileExists(outDir, relativePath)
|
104
76
|
);
|
@@ -106,7 +78,7 @@ async function callTypescript({
|
|
106
78
|
}
|
107
79
|
if (file.endsWith(".d.mts")) {
|
108
80
|
const transformedCode = inlineExtensions.inlineExtensionsMjs(
|
109
|
-
ts,
|
81
|
+
ts.ts,
|
110
82
|
content,
|
111
83
|
makeFileExists(outDir, relativePath)
|
112
84
|
);
|
@@ -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 } 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:
|
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, cjsOutDir, \".d.ts\");\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 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,cAA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+5,9 @@ const fs = require("node:fs/promises");
|
|
5
5
|
const log = require("../log.js");
|
6
6
|
async function copyStaticFilesTask(sourceDir, outDir) {
|
7
7
|
const files = await copyStaticFiles({
|
8
|
+
// WARN only files inside sourceDir are supported because of node_modules
|
9
|
+
// Fix this behavior if needed in the future
|
10
|
+
// This place is not tested because I don't want to test node_modules or some same folders
|
8
11
|
relativeFiles: /* @__PURE__ */ new Set(["readme.md", "license", "license.txt"]),
|
9
12
|
sourceDir,
|
10
13
|
outDir
|
@@ -18,9 +21,8 @@ async function copyStaticFiles({
|
|
18
21
|
relativeFiles
|
19
22
|
}) {
|
20
23
|
const dirFiles = new Map(
|
21
|
-
|
22
|
-
|
23
|
-
)
|
24
|
+
// avoid {recursive: true} because of node_modules
|
25
|
+
(await fs.readdir(sourceDir)).map((f) => [f.toLowerCase(), f])
|
24
26
|
);
|
25
27
|
const res = /* @__PURE__ */ new Set();
|
26
28
|
for (const file of relativeFiles) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"copyStaticFilesTask.js","sources":["../../../../../src/tasks/copyStaticFilesTask.ts"],"sourcesContent":["import { join } from \"node:path\";\nimport { copyFile, readdir } from \"node:fs/promises\";\nimport { okLog } from \"../log.js\";\n\nexport async function copyStaticFilesTask(sourceDir: string, outDir: string) {\n const files = await copyStaticFiles({\n relativeFiles: new Set([\"readme.md\", \"license\", \"license.txt\"]),\n sourceDir,\n outDir,\n });\n\n okLog(\"Static files:\", [...files].join(\", \"));\n\n return files;\n}\n\ntype CopyStaticFilesOptions = {\n relativeFiles: Set<string>;\n sourceDir: string;\n outDir: string;\n};\n\nasync function copyStaticFiles({\n sourceDir,\n outDir,\n relativeFiles,\n}: CopyStaticFilesOptions) {\n const dirFiles = new Map(\n
|
1
|
+
{"version":3,"file":"copyStaticFilesTask.js","sources":["../../../../../src/tasks/copyStaticFilesTask.ts"],"sourcesContent":["import { join } from \"node:path\";\nimport { copyFile, readdir } from \"node:fs/promises\";\nimport { okLog } from \"../log.js\";\n\nexport async function copyStaticFilesTask(sourceDir: string, outDir: string) {\n const files = await copyStaticFiles({\n // WARN only files inside sourceDir are supported because of node_modules\n // Fix this behavior if needed in the future\n // This place is not tested because I don't want to test node_modules or some same folders\n relativeFiles: new Set([\"readme.md\", \"license\", \"license.txt\"]),\n sourceDir,\n outDir,\n });\n\n okLog(\"Static files:\", [...files].join(\", \"));\n\n return files;\n}\n\ntype CopyStaticFilesOptions = {\n relativeFiles: Set<string>;\n sourceDir: string;\n outDir: string;\n};\n\nasync function copyStaticFiles({\n sourceDir,\n outDir,\n relativeFiles,\n}: CopyStaticFilesOptions) {\n const dirFiles = new Map(\n // avoid {recursive: true} because of node_modules\n (await readdir(sourceDir)).map((f) => [f.toLowerCase(), f] as const),\n );\n\n const res = new Set<string>();\n for (const file of relativeFiles) {\n try {\n const matchingFile = dirFiles.get(file.toLowerCase());\n\n if (matchingFile) {\n const outFilePath = join(outDir, matchingFile);\n const filePath = join(sourceDir, matchingFile);\n await copyFile(filePath, outFilePath);\n res.add(matchingFile);\n }\n } catch {}\n }\n\n return res;\n}\n"],"names":["okLog","readdir","join","copyFile"],"mappings":";;;;;AAIsB,eAAA,oBAAoB,WAAmB,QAAgB;AACrE,QAAA,QAAQ,MAAM,gBAAgB;AAAA;AAAA;AAAA;AAAA,IAIlC,eAAmB,oBAAA,IAAI,CAAC,aAAa,WAAW,aAAa,CAAC;AAAA,IAC9D;AAAA,IACA;AAAA,EAAA,CACD;AAEDA,MAAA,MAAM,iBAAiB,CAAC,GAAG,KAAK,EAAE,KAAK,IAAI,CAAC;AAErC,SAAA;AACT;AAQA,eAAe,gBAAgB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AACF,GAA2B;AACzB,QAAM,WAAW,IAAI;AAAA;AAAA,KAElB,MAAMC,GAAAA,QAAQ,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,YAAe,GAAA,CAAC,CAAU;AAAA,EACrE;AAEM,QAAA,0BAAU,IAAY;AAC5B,aAAW,QAAQ,eAAe;AAC5B,QAAA;AACF,YAAM,eAAe,SAAS,IAAI,KAAK,aAAa;AAEpD,UAAI,cAAc;AACV,cAAA,cAAcC,KAAAA,KAAK,QAAQ,YAAY;AACvC,cAAA,WAAWA,KAAAA,KAAK,WAAW,YAAY;AACvC,cAAAC,GAAA,SAAS,UAAU,WAAW;AACpC,YAAI,IAAI,YAAY;AAAA,MAAA;AAAA,IACtB,QACM;AAAA,IAAA;AAAA,EAAC;AAGJ,SAAA;AACT;;"}
|
@@ -1,11 +1,23 @@
|
|
1
1
|
import { type PackageJson } from "./packageJson.js";
|
2
2
|
import semver from "semver";
|
3
|
+
import type { Dirs } from "./resolveDirs.js";
|
4
|
+
export type TS = {
|
5
|
+
ts: typeof import("typescript");
|
6
|
+
parsedConfig: import("typescript").ParsedCommandLine;
|
7
|
+
host: import("typescript").CompilerHost;
|
8
|
+
};
|
3
9
|
export type DetectedModules = {
|
4
|
-
ts?:
|
10
|
+
ts?: TS;
|
5
11
|
babel?: typeof import("@babel/core");
|
6
12
|
react?: "legacy" | "modern";
|
7
13
|
};
|
8
14
|
type DepType = "dependencies" | "devDependencies" | "peerDependencies" | "optionalDependencies";
|
9
15
|
export declare function getMinVersion(packageJson: PackageJson, depName: string, exclude: DepType[]): semver.SemVer | null;
|
10
|
-
export declare function detectModules(packageJson: PackageJson): Promise<
|
16
|
+
export declare function detectModules(packageJson: PackageJson, dirs: Dirs): Promise<{
|
17
|
+
error: false;
|
18
|
+
modules: DetectedModules;
|
19
|
+
} | {
|
20
|
+
error: true;
|
21
|
+
errors: Array<string>;
|
22
|
+
}>;
|
11
23
|
export {};
|
@@ -2,7 +2,7 @@ import "node:fs/promises";
|
|
2
2
|
import "zod";
|
3
3
|
import "node:path";
|
4
4
|
import semver from "semver";
|
5
|
-
import { log,
|
5
|
+
import { log, lineLog, errorLog, okLog, warnLog } from "./log.mjs";
|
6
6
|
function getMinVersion(packageJson, depName, exclude) {
|
7
7
|
var _a;
|
8
8
|
const allDepKeys = /* @__PURE__ */ new Set([
|
@@ -60,19 +60,68 @@ async function detectReact(packageJson) {
|
|
60
60
|
}
|
61
61
|
errorLog("react");
|
62
62
|
}
|
63
|
-
async function
|
64
|
-
|
65
|
-
log("Detecting modules");
|
63
|
+
async function detectTypescript(dirs) {
|
64
|
+
let ts;
|
66
65
|
try {
|
67
|
-
|
68
|
-
okLog("typescript, version:", result.ts.version);
|
66
|
+
ts = (await import("typescript")).default;
|
69
67
|
} catch {
|
70
68
|
errorLog("typescript");
|
69
|
+
return;
|
70
|
+
}
|
71
|
+
okLog("typescript, version:", ts.version);
|
72
|
+
const configFilePath = ts.findConfigFile(dirs.sourceDir, ts.sys.fileExists);
|
73
|
+
if (!configFilePath) {
|
74
|
+
throw new Error(
|
75
|
+
"Cannot find a tsconfig.json file. You should declare it. Please, read the https://github.com/XaveScor/smartbundle/issues/131 for more information"
|
76
|
+
);
|
77
|
+
}
|
78
|
+
const configFile = ts.readConfigFile(configFilePath, ts.sys.readFile);
|
79
|
+
if (configFile.error) {
|
80
|
+
const readableError = ts.flattenDiagnosticMessageText(
|
81
|
+
configFile.error.messageText,
|
82
|
+
"\n"
|
83
|
+
);
|
84
|
+
throw new Error(`Cannot read tsconfig.json file, error: ${readableError}`);
|
85
|
+
}
|
86
|
+
const parsedConfig = ts.parseJsonConfigFileContent(
|
87
|
+
configFile.config,
|
88
|
+
ts.sys,
|
89
|
+
dirs.sourceDir,
|
90
|
+
{
|
91
|
+
declaration: true,
|
92
|
+
emitDeclarationOnly: true,
|
93
|
+
strict: false,
|
94
|
+
strictNullChecks: false,
|
95
|
+
strictFunctionTypes: false,
|
96
|
+
strictPropertyInitialization: false,
|
97
|
+
skipLibCheck: true,
|
98
|
+
skipDefaultLibCheck: true,
|
99
|
+
outDir: "",
|
100
|
+
// https://github.com/XaveScor/bobrik/issues/22#issuecomment-2308552352
|
101
|
+
noEmit: false
|
102
|
+
},
|
103
|
+
configFilePath
|
104
|
+
);
|
105
|
+
if (!parsedConfig.options.verbatimModuleSyntax) {
|
106
|
+
throw new Error(
|
107
|
+
"verbatimModuleSyntax should be enabled in tsconfig.json. Read https://github.com/XaveScor/smartbundle/issues/131 for more explanation.\nYou also can upvote the issue if you need the support of verbatimModuleSyntax: false in your library"
|
108
|
+
);
|
109
|
+
}
|
110
|
+
const host = ts.createCompilerHost(parsedConfig.options);
|
111
|
+
return { ts, parsedConfig, host };
|
112
|
+
}
|
113
|
+
async function detectModules(packageJson, dirs) {
|
114
|
+
try {
|
115
|
+
const result = {};
|
116
|
+
log("Detecting modules");
|
117
|
+
result.ts = await detectTypescript(dirs);
|
118
|
+
result.babel = await detectBabel(packageJson);
|
119
|
+
result.react = await detectReact(packageJson);
|
120
|
+
lineLog();
|
121
|
+
return { error: false, modules: result };
|
122
|
+
} catch (e) {
|
123
|
+
return { error: true, errors: [e.message] };
|
71
124
|
}
|
72
|
-
result.babel = await detectBabel(packageJson);
|
73
|
-
result.react = await detectReact(packageJson);
|
74
|
-
lineLog();
|
75
|
-
return result;
|
76
125
|
}
|
77
126
|
export {
|
78
127
|
detectModules,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"detectModules.mjs","sources":["../../../../src/detectModules.ts"],"sourcesContent":["import { type PackageJson } from \"./packageJson.js\";\nimport semver from \"semver\";\nimport { okLog, errorLog, log, lineLog, warnLog } from \"./log.js\";\n\nexport type
|
1
|
+
{"version":3,"file":"detectModules.mjs","sources":["../../../../src/detectModules.ts"],"sourcesContent":["import { type PackageJson } from \"./packageJson.js\";\nimport semver from \"semver\";\nimport { okLog, errorLog, log, lineLog, warnLog } from \"./log.js\";\nimport type { Dirs } from \"./resolveDirs.js\";\n\nexport type TS = {\n ts: typeof import(\"typescript\");\n parsedConfig: import(\"typescript\").ParsedCommandLine;\n host: import(\"typescript\").CompilerHost;\n};\nexport type DetectedModules = {\n ts?: TS;\n babel?: typeof import(\"@babel/core\");\n react?: \"legacy\" | \"modern\";\n};\n\ntype DepType =\n | \"dependencies\"\n | \"devDependencies\"\n | \"peerDependencies\"\n | \"optionalDependencies\";\nexport function getMinVersion(\n packageJson: PackageJson,\n depName: string,\n exclude: DepType[],\n): semver.SemVer | null {\n const allDepKeys = new Set<DepType>([\n \"dependencies\",\n \"devDependencies\",\n \"peerDependencies\",\n \"optionalDependencies\",\n ]);\n for (const e of exclude) {\n allDepKeys.delete(e);\n }\n\n let minVersion: semver.SemVer | null = null;\n for (const depKey of allDepKeys) {\n const depVersion = packageJson[depKey]?.[depName];\n if (depVersion) {\n const version = semver.minVersion(depVersion);\n if (!version) {\n warnLog(\"node-semver cannot parse version of\", depName, \"from\", depKey);\n warnLog(\"Version:\", depVersion);\n continue;\n }\n if (!minVersion) {\n minVersion = version;\n continue;\n }\n if (semver.lt(version, minVersion)) {\n minVersion = version;\n }\n }\n }\n\n return minVersion;\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 = getMinVersion(packageJson, \"react\", [\"devDependencies\"]);\n if (reactVersion) {\n const isLegacy = semver.lt(reactVersion, \"17.0.0\");\n const transform = isLegacy ? \"legacy\" : \"modern\";\n okLog(\n `react, min version: ${reactVersion.version}. Transform: ${transform}`,\n );\n return transform;\n }\n errorLog(\"react\");\n}\n\nasync function detectTypescript(dirs: Dirs): Promise<TS | undefined> {\n let ts: typeof import(\"typescript\");\n try {\n // ts <=4.3 has no named exports. The all methods is located in the default export\n ts = (await import(\"typescript\")).default;\n } catch {\n errorLog(\"typescript\");\n return;\n }\n\n okLog(\"typescript, version:\", ts.version);\n\n const configFilePath = ts.findConfigFile(dirs.sourceDir, ts.sys.fileExists);\n if (!configFilePath) {\n throw new Error(\n \"Cannot find a tsconfig.json file. You should declare it. Please, read the https://github.com/XaveScor/smartbundle/issues/131 for more information\",\n );\n }\n const configFile = ts.readConfigFile(configFilePath, ts.sys.readFile);\n if (configFile.error) {\n const readableError = ts.flattenDiagnosticMessageText(\n configFile.error.messageText,\n \"\\n\",\n );\n throw new Error(`Cannot read tsconfig.json file, error: ${readableError}`);\n }\n const parsedConfig = ts.parseJsonConfigFileContent(\n configFile.config,\n ts.sys,\n dirs.sourceDir,\n {\n declaration: true,\n emitDeclarationOnly: true,\n strict: false,\n strictNullChecks: false,\n strictFunctionTypes: false,\n strictPropertyInitialization: false,\n skipLibCheck: true,\n skipDefaultLibCheck: true,\n outDir: \"\",\n // https://github.com/XaveScor/bobrik/issues/22#issuecomment-2308552352\n noEmit: false,\n },\n configFilePath,\n );\n\n if (!parsedConfig.options.verbatimModuleSyntax) {\n throw new Error(\n \"verbatimModuleSyntax should be enabled in tsconfig.json. Read https://github.com/XaveScor/smartbundle/issues/131 for more explanation.\\n\" +\n \"You also can upvote the issue if you need the support of verbatimModuleSyntax: false in your library\",\n );\n }\n\n const host = ts.createCompilerHost(parsedConfig.options);\n\n return { ts, parsedConfig, host };\n}\n\nexport async function detectModules(\n packageJson: PackageJson,\n dirs: Dirs,\n): Promise<\n | { error: false; modules: DetectedModules }\n | { error: true; errors: Array<string> }\n> {\n try {\n const result: DetectedModules = {};\n log(\"Detecting modules\");\n\n result.ts = await detectTypescript(dirs);\n result.babel = await detectBabel(packageJson);\n result.react = await detectReact(packageJson);\n\n lineLog();\n return { error: false, modules: result };\n } catch (e: any) {\n return { error: true, errors: [e.message] };\n }\n}\n"],"names":[],"mappings":";;;;;AAqBgB,SAAA,cACd,aACA,SACA,SACsB;;AAChB,QAAA,iCAAiB,IAAa;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AACD,aAAW,KAAK,SAAS;AACvB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").UserConfig
|
2
|
+
export declare function defineViteConfig(args?: Args): Promise<import("vite").UserConfig | {
|
3
|
+
error: boolean;
|
4
|
+
errors: string[];
|
5
|
+
}>;
|
3
6
|
type RunResult = {
|
4
7
|
error: false;
|
5
8
|
} | {
|
@@ -30,7 +30,11 @@ async function defineViteConfig(args = {}) {
|
|
30
30
|
console.error(packageJson);
|
31
31
|
throw new Error("Failed to parse package.json");
|
32
32
|
}
|
33
|
-
const
|
33
|
+
const modulesResult = await detectModules(packageJson, dirs);
|
34
|
+
if (modulesResult.error) {
|
35
|
+
return { error: true, errors: modulesResult.errors };
|
36
|
+
}
|
37
|
+
const { modules } = modulesResult;
|
34
38
|
const { viteConfig } = createViteConfig({ dirs, packageJson, modules });
|
35
39
|
return viteConfig;
|
36
40
|
}
|
@@ -43,7 +47,11 @@ async function run(args) {
|
|
43
47
|
if (Array.isArray(packageJson)) {
|
44
48
|
return { error: true, errors: packageJson };
|
45
49
|
}
|
46
|
-
const
|
50
|
+
const modulesResult = await detectModules(packageJson, dirs);
|
51
|
+
if (modulesResult.error) {
|
52
|
+
return { error: true, errors: modulesResult.errors };
|
53
|
+
}
|
54
|
+
const { modules } = modulesResult;
|
47
55
|
const { viteConfig, entrypoints, bins } = createViteConfig({
|
48
56
|
dirs,
|
49
57
|
packageJson,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.mjs","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
|
1
|
+
{"version":3,"file":"index.mjs","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({ 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 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 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":[],"mappings":";;;;;;;;;;;;;;;;;AAkBA,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;AAC3C,aAAA;AACL,QAAA,OAAO,YAAY,IAAI;AAC7B,QAAM,EAAE,WAAW,QAAQ,YAAgB,IAAA;AAE3C,QAAM,GAAG,QAAQ,EAAE,WAAW,MAAM,OAAO,MAAM;AACjD,QAAM,MAAM,QAAQ,EAAE,WAAW,MAAM;AACvC,QAAM,cAAc,MAAM,iBAAiB,EAAE,WAAW,aAAa;AAEjE,MAAA,MAAM,QAAQ,WAAW,GAAG;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,EAAA;AAGzB,QAAA,iBAAiB,QAAQ,aAAa;AAAA,IAC1C;AAAA,IACA;AAAA,EAAA,CACD;AAEO,UAAA;AACR,MAAI,qBAAqB,SAAS,WAAW,MAAM,CAAC,EAAE;AAC/C,SAAA,EAAE,OAAO,MAAM;AACxB;"}
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import { type PackageJson } from "../../packageJson.js";
|
2
|
+
import { type TS } from "../../detectModules.js";
|
2
3
|
import { type Dirs } from "../../resolveDirs.js";
|
3
4
|
type BuildTypesOptions = {
|
4
|
-
ts:
|
5
|
+
ts: TS;
|
5
6
|
dirs: Dirs;
|
6
7
|
packageJson: PackageJson;
|
7
8
|
tsEntrypoints: string[];
|
@@ -21,40 +21,12 @@ async function callTypescript({
|
|
21
21
|
packageJson
|
22
22
|
}) {
|
23
23
|
const { sourceDir, outDir, esmOutDir, cjsOutDir } = dirs;
|
24
|
-
const configPath = path.join(sourceDir, "tsconfig.json");
|
25
|
-
const configFile = ts.readConfigFile(
|
26
|
-
configPath,
|
27
|
-
(path2) => (
|
28
|
-
// https://github.com/XaveScor/bobrik/issues/22
|
29
|
-
fs.readFileSync(path2, "utf-8")
|
30
|
-
)
|
31
|
-
);
|
32
|
-
const parsedCommandLine = ts.parseJsonConfigFileContent(
|
33
|
-
configFile.config,
|
34
|
-
ts.sys,
|
35
|
-
sourceDir,
|
36
|
-
{
|
37
|
-
declaration: true,
|
38
|
-
emitDeclarationOnly: true,
|
39
|
-
strict: false,
|
40
|
-
strictNullChecks: false,
|
41
|
-
strictFunctionTypes: false,
|
42
|
-
strictPropertyInitialization: false,
|
43
|
-
skipLibCheck: true,
|
44
|
-
skipDefaultLibCheck: true,
|
45
|
-
outDir: "",
|
46
|
-
// https://github.com/XaveScor/bobrik/issues/22#issuecomment-2308552352
|
47
|
-
noEmit: false
|
48
|
-
},
|
49
|
-
configPath
|
50
|
-
);
|
51
|
-
const host = ts.createCompilerHost(parsedCommandLine.options);
|
52
24
|
const sourceToCjsDtsMap = /* @__PURE__ */ new Map();
|
53
25
|
const sourceToEsmDtsMap = /* @__PURE__ */ new Map();
|
54
|
-
const program = ts.createProgram(
|
26
|
+
const program = ts.ts.createProgram(
|
55
27
|
tsEntrypoints,
|
56
|
-
|
57
|
-
host
|
28
|
+
ts.parsedConfig.options,
|
29
|
+
ts.host
|
58
30
|
);
|
59
31
|
program.emit(void 0, (fileName, data) => {
|
60
32
|
const relativePath = path.relative(sourceDir, fileName);
|
@@ -78,7 +50,7 @@ async function callTypescript({
|
|
78
50
|
const relativePath = path.relative(outDir, file);
|
79
51
|
if (file.endsWith(".d.ts")) {
|
80
52
|
const transformedCode = inlineExtensionsCjs(
|
81
|
-
ts,
|
53
|
+
ts.ts,
|
82
54
|
content,
|
83
55
|
makeFileExists(outDir, relativePath)
|
84
56
|
);
|
@@ -86,7 +58,7 @@ async function callTypescript({
|
|
86
58
|
}
|
87
59
|
if (file.endsWith(".d.mts")) {
|
88
60
|
const transformedCode = inlineExtensionsMjs(
|
89
|
-
ts,
|
61
|
+
ts.ts,
|
90
62
|
content,
|
91
63
|
makeFileExists(outDir, relativePath)
|
92
64
|
);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"callTypescript.mjs","sources":["../../../../../../src/tasks/buildTypesTask/callTypescript.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as fs from \"node:fs\";\nimport {\n inlineExtensionsMjs,\n inlineExtensionsCjs,\n} from \"./inlineExtensions.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { getMinVersion } 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:
|
1
|
+
{"version":3,"file":"callTypescript.mjs","sources":["../../../../../../src/tasks/buildTypesTask/callTypescript.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as fs from \"node:fs\";\nimport {\n inlineExtensionsMjs,\n inlineExtensionsCjs,\n} from \"./inlineExtensions.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { getMinVersion, type TS } from \"../../detectModules.js\";\nimport { BuildError } from \"../../error.js\";\nimport { findTypingsPackages } from \"./findTypingsPackages.js\";\nimport { findTypingsNames } from \"./findTypingsNames.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesOptions = {\n ts: TS;\n dirs: Dirs;\n packageJson: PackageJson;\n tsEntrypoints: string[];\n outDir: string;\n};\n\nfunction makeFileExists(outDir: string, filePath: string) {\n return (p: string) => {\n const dir = path.join(outDir, path.dirname(filePath));\n return fs.existsSync(path.join(dir, p));\n };\n}\n\nexport async function callTypescript({\n ts,\n dirs,\n tsEntrypoints,\n packageJson,\n}: BuildTypesOptions) {\n const { sourceDir, outDir, esmOutDir, cjsOutDir } = dirs;\n\n // <build d.ts>\n const sourceToCjsDtsMap = new Map<string, string>();\n const sourceToEsmDtsMap = new Map<string, string>();\n const program = ts.ts.createProgram(\n tsEntrypoints,\n ts.parsedConfig.options,\n ts.host,\n );\n program.emit(undefined, (fileName, data) => {\n // .d.ts for cjs because \"type\": \"commonjs\" in package.json\n // .d.mts for esm\n const relativePath = path.relative(sourceDir, fileName);\n const sourceFileName = fileName.replace(/\\.d\\.ts$/, \".ts\"); // Assuming source files have .ts extension\n\n const finalEsmPath = path.join(esmOutDir, relativePath);\n const esmFinalPath = finalEsmPath.replace(/\\.d\\.ts$/, \".d.mts\");\n sourceToEsmDtsMap.set(sourceFileName, esmFinalPath);\n fs.mkdirSync(path.dirname(esmFinalPath), { recursive: true });\n fs.writeFileSync(esmFinalPath, data);\n\n const finalCjsPath = path.join(cjsOutDir, relativePath);\n fs.mkdirSync(path.dirname(finalCjsPath), { recursive: true });\n const cjsFinalPath = finalCjsPath;\n fs.writeFileSync(cjsFinalPath, data);\n sourceToCjsDtsMap.set(sourceFileName, cjsFinalPath);\n });\n // </build d.ts>\n\n // <fix vscode typings>\n for (const file of [\n ...sourceToCjsDtsMap.values(),\n ...sourceToEsmDtsMap.values(),\n ]) {\n const content = fs.readFileSync(file, \"utf-8\");\n const relativePath = path.relative(outDir, file);\n if (file.endsWith(\".d.ts\")) {\n const transformedCode = inlineExtensionsCjs(\n ts.ts,\n content,\n makeFileExists(outDir, relativePath),\n );\n fs.writeFileSync(file, transformedCode);\n }\n if (file.endsWith(\".d.mts\")) {\n const transformedCode = inlineExtensionsMjs(\n ts.ts,\n content,\n makeFileExists(outDir, relativePath),\n );\n fs.writeFileSync(file, transformedCode);\n }\n }\n // </fix vscode typings>\n\n // <find all libraries names>\n const packages = new Set<string>();\n for (const sourceEntrypoint of tsEntrypoints) {\n const esmEntrypoint = sourceToEsmDtsMap.get(sourceEntrypoint);\n if (esmEntrypoint) {\n const localPackages = findTypingsNames(\n esmEntrypoint,\n esmOutDir,\n \".d.mts\",\n );\n for (const p of localPackages) {\n packages.add(p);\n }\n }\n\n const cjsEntrypoint = sourceToCjsDtsMap.get(sourceEntrypoint);\n if (cjsEntrypoint) {\n const localPackages = findTypingsNames(cjsEntrypoint, cjsOutDir, \".d.ts\");\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 packages,\n sourceDir,\n );\n for (const lib of existingTypingPackages) {\n if (\n getMinVersion(packageJson, lib, [\n \"optionalDependencies\",\n \"devDependencies\",\n ]) == null\n ) {\n missingTypings.add(lib);\n }\n }\n if (missingTypings.size > 0) {\n const libsList = [...missingTypings].map((x) => `\"${x}\"`).join(\", \");\n throw new BuildError(\n `The typings won't installed in bundled package: ${libsList}. Please install them into dependencies or peerDependencies.`,\n );\n }\n // </check not installed typings libraries>\n\n return {\n sourceToCjsDtsMap,\n sourceToEsmDtsMap,\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;AAqBA,SAAS,eAAe,QAAgB,UAAkB;AACxD,SA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3,6 +3,9 @@ import { readdir, copyFile } from "node:fs/promises";
|
|
3
3
|
import { okLog } from "../log.mjs";
|
4
4
|
async function copyStaticFilesTask(sourceDir, outDir) {
|
5
5
|
const files = await copyStaticFiles({
|
6
|
+
// WARN only files inside sourceDir are supported because of node_modules
|
7
|
+
// Fix this behavior if needed in the future
|
8
|
+
// This place is not tested because I don't want to test node_modules or some same folders
|
6
9
|
relativeFiles: /* @__PURE__ */ new Set(["readme.md", "license", "license.txt"]),
|
7
10
|
sourceDir,
|
8
11
|
outDir
|
@@ -16,9 +19,8 @@ async function copyStaticFiles({
|
|
16
19
|
relativeFiles
|
17
20
|
}) {
|
18
21
|
const dirFiles = new Map(
|
19
|
-
|
20
|
-
|
21
|
-
)
|
22
|
+
// avoid {recursive: true} because of node_modules
|
23
|
+
(await readdir(sourceDir)).map((f) => [f.toLowerCase(), f])
|
22
24
|
);
|
23
25
|
const res = /* @__PURE__ */ new Set();
|
24
26
|
for (const file of relativeFiles) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"copyStaticFilesTask.mjs","sources":["../../../../../src/tasks/copyStaticFilesTask.ts"],"sourcesContent":["import { join } from \"node:path\";\nimport { copyFile, readdir } from \"node:fs/promises\";\nimport { okLog } from \"../log.js\";\n\nexport async function copyStaticFilesTask(sourceDir: string, outDir: string) {\n const files = await copyStaticFiles({\n relativeFiles: new Set([\"readme.md\", \"license\", \"license.txt\"]),\n sourceDir,\n outDir,\n });\n\n okLog(\"Static files:\", [...files].join(\", \"));\n\n return files;\n}\n\ntype CopyStaticFilesOptions = {\n relativeFiles: Set<string>;\n sourceDir: string;\n outDir: string;\n};\n\nasync function copyStaticFiles({\n sourceDir,\n outDir,\n relativeFiles,\n}: CopyStaticFilesOptions) {\n const dirFiles = new Map(\n
|
1
|
+
{"version":3,"file":"copyStaticFilesTask.mjs","sources":["../../../../../src/tasks/copyStaticFilesTask.ts"],"sourcesContent":["import { join } from \"node:path\";\nimport { copyFile, readdir } from \"node:fs/promises\";\nimport { okLog } from \"../log.js\";\n\nexport async function copyStaticFilesTask(sourceDir: string, outDir: string) {\n const files = await copyStaticFiles({\n // WARN only files inside sourceDir are supported because of node_modules\n // Fix this behavior if needed in the future\n // This place is not tested because I don't want to test node_modules or some same folders\n relativeFiles: new Set([\"readme.md\", \"license\", \"license.txt\"]),\n sourceDir,\n outDir,\n });\n\n okLog(\"Static files:\", [...files].join(\", \"));\n\n return files;\n}\n\ntype CopyStaticFilesOptions = {\n relativeFiles: Set<string>;\n sourceDir: string;\n outDir: string;\n};\n\nasync function copyStaticFiles({\n sourceDir,\n outDir,\n relativeFiles,\n}: CopyStaticFilesOptions) {\n const dirFiles = new Map(\n // avoid {recursive: true} because of node_modules\n (await readdir(sourceDir)).map((f) => [f.toLowerCase(), f] as const),\n );\n\n const res = new Set<string>();\n for (const file of relativeFiles) {\n try {\n const matchingFile = dirFiles.get(file.toLowerCase());\n\n if (matchingFile) {\n const outFilePath = join(outDir, matchingFile);\n const filePath = join(sourceDir, matchingFile);\n await copyFile(filePath, outFilePath);\n res.add(matchingFile);\n }\n } catch {}\n }\n\n return res;\n}\n"],"names":[],"mappings":";;;AAIsB,eAAA,oBAAoB,WAAmB,QAAgB;AACrE,QAAA,QAAQ,MAAM,gBAAgB;AAAA;AAAA;AAAA;AAAA,IAIlC,eAAmB,oBAAA,IAAI,CAAC,aAAa,WAAW,aAAa,CAAC;AAAA,IAC9D;AAAA,IACA;AAAA,EAAA,CACD;AAED,QAAM,iBAAiB,CAAC,GAAG,KAAK,EAAE,KAAK,IAAI,CAAC;AAErC,SAAA;AACT;AAQA,eAAe,gBAAgB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AACF,GAA2B;AACzB,QAAM,WAAW,IAAI;AAAA;AAAA,KAElB,MAAM,QAAQ,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,YAAe,GAAA,CAAC,CAAU;AAAA,EACrE;AAEM,QAAA,0BAAU,IAAY;AAC5B,aAAW,QAAQ,eAAe;AAC5B,QAAA;AACF,YAAM,eAAe,SAAS,IAAI,KAAK,aAAa;AAEpD,UAAI,cAAc;AACV,cAAA,cAAc,KAAK,QAAQ,YAAY;AACvC,cAAA,WAAW,KAAK,WAAW,YAAY;AACvC,cAAA,SAAS,UAAU,WAAW;AACpC,YAAI,IAAI,YAAY;AAAA,MAAA;AAAA,IACtB,QACM;AAAA,IAAA;AAAA,EAAC;AAGJ,SAAA;AACT;"}
|