smartbundle 0.15.0-alpha.0 → 0.15.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/__bin__/smartbundle-monorepo-link.js +2 -0
- package/__compiled__/cjs/src/args.d.ts +9 -1
- package/__compiled__/cjs/src/args.js +3 -0
- package/__compiled__/cjs/src/args.js.map +1 -1
- package/__compiled__/cjs/src/detectModules.d.ts +25 -11
- package/__compiled__/cjs/src/detectModules.js +165 -28
- package/__compiled__/cjs/src/detectModules.js.map +1 -1
- package/__compiled__/cjs/src/errors.js +4 -0
- package/__compiled__/cjs/src/errors.js.map +1 -1
- package/__compiled__/cjs/src/index.d.ts +1 -1
- package/__compiled__/cjs/src/index.js +11 -5
- package/__compiled__/cjs/src/index.js.map +1 -1
- package/__compiled__/cjs/src/monorepo/buildAll.js +62 -0
- package/__compiled__/cjs/src/monorepo/buildAll.js.map +1 -0
- package/__compiled__/cjs/src/monorepo/convertPackageJson.d.ts +31 -0
- package/__compiled__/cjs/src/monorepo/convertPackageJson.js +40 -0
- package/__compiled__/cjs/src/monorepo/convertPackageJson.js.map +1 -0
- package/__compiled__/cjs/src/monorepo/createLinkPackages/createLinkPackages.js +92 -0
- package/__compiled__/cjs/src/monorepo/createLinkPackages/createLinkPackages.js.map +1 -0
- package/__compiled__/cjs/src/monorepo/link.js +11 -0
- package/__compiled__/cjs/src/monorepo/link.js.map +1 -0
- package/__compiled__/cjs/src/monorepo/parseMonorepo/parseMonorepo.js +106 -0
- package/__compiled__/cjs/src/monorepo/parseMonorepo/parseMonorepo.js.map +1 -0
- package/__compiled__/cjs/src/packageJson.d.ts +5 -0
- package/__compiled__/cjs/src/packageJson.js +2 -0
- package/__compiled__/cjs/src/packageJson.js.map +1 -1
- package/__compiled__/cjs/src/plugins/babel/index.js +1 -1
- package/__compiled__/cjs/src/plugins/babel/index.js.map +1 -1
- package/__compiled__/cjs/src/plugins/react/index.js +3 -2
- package/__compiled__/cjs/src/plugins/react/index.js.map +1 -1
- package/__compiled__/cjs/src/run.js +47 -8
- package/__compiled__/cjs/src/run.js.map +1 -1
- package/__compiled__/cjs/src/tasks/buildTypesTask/callTypescript.d.ts +2 -2
- package/__compiled__/cjs/src/tasks/buildTypesTask/callTypescript.js.map +1 -1
- package/__compiled__/cjs/src/tasks/buildTypesTask/findTypingsNames.d.ts +2 -2
- package/__compiled__/cjs/src/tasks/buildTypesTask/findTypingsNames.js.map +1 -1
- package/__compiled__/cjs/src/tasks/buildTypesTask/findTypingsPackages.d.ts +2 -2
- package/__compiled__/cjs/src/tasks/buildTypesTask/findTypingsPackages.js.map +1 -1
- package/__compiled__/cjs/src/tasks/gitignoreTask.d.ts +6 -0
- package/__compiled__/cjs/src/tasks/gitignoreTask.js +14 -0
- package/__compiled__/cjs/src/tasks/gitignoreTask.js.map +1 -0
- package/__compiled__/cjs/src/writePackageJson.js +2 -33
- package/__compiled__/cjs/src/writePackageJson.js.map +1 -1
- package/__compiled__/esm/src/args.d.mts +9 -1
- package/__compiled__/esm/src/args.mjs +3 -0
- package/__compiled__/esm/src/args.mjs.map +1 -1
- package/__compiled__/esm/src/detectModules.d.mts +25 -11
- package/__compiled__/esm/src/detectModules.mjs +165 -28
- package/__compiled__/esm/src/detectModules.mjs.map +1 -1
- package/__compiled__/esm/src/errors.mjs +4 -0
- package/__compiled__/esm/src/errors.mjs.map +1 -1
- package/__compiled__/esm/src/index.d.mts +1 -1
- package/__compiled__/esm/src/index.mjs +11 -5
- package/__compiled__/esm/src/index.mjs.map +1 -1
- package/__compiled__/esm/src/monorepo/buildAll.mjs +62 -0
- package/__compiled__/esm/src/monorepo/buildAll.mjs.map +1 -0
- package/__compiled__/esm/src/monorepo/convertPackageJson.d.mts +31 -0
- package/__compiled__/esm/src/monorepo/convertPackageJson.mjs +40 -0
- package/__compiled__/esm/src/monorepo/convertPackageJson.mjs.map +1 -0
- package/__compiled__/esm/src/monorepo/createLinkPackages/createLinkPackages.mjs +92 -0
- package/__compiled__/esm/src/monorepo/createLinkPackages/createLinkPackages.mjs.map +1 -0
- package/__compiled__/esm/src/monorepo/link.mjs +10 -0
- package/__compiled__/esm/src/monorepo/link.mjs.map +1 -0
- package/__compiled__/esm/src/monorepo/parseMonorepo/parseMonorepo.mjs +106 -0
- package/__compiled__/esm/src/monorepo/parseMonorepo/parseMonorepo.mjs.map +1 -0
- package/__compiled__/esm/src/packageJson.d.mts +5 -0
- package/__compiled__/esm/src/packageJson.mjs +2 -0
- package/__compiled__/esm/src/packageJson.mjs.map +1 -1
- package/__compiled__/esm/src/plugins/babel/index.mjs +1 -1
- package/__compiled__/esm/src/plugins/babel/index.mjs.map +1 -1
- package/__compiled__/esm/src/plugins/react/index.mjs +3 -2
- package/__compiled__/esm/src/plugins/react/index.mjs.map +1 -1
- package/__compiled__/esm/src/run.mjs +47 -8
- package/__compiled__/esm/src/run.mjs.map +1 -1
- package/__compiled__/esm/src/tasks/buildTypesTask/callTypescript.d.mts +2 -2
- package/__compiled__/esm/src/tasks/buildTypesTask/callTypescript.mjs.map +1 -1
- package/__compiled__/esm/src/tasks/buildTypesTask/findTypingsNames.d.mts +2 -2
- package/__compiled__/esm/src/tasks/buildTypesTask/findTypingsNames.mjs.map +1 -1
- package/__compiled__/esm/src/tasks/buildTypesTask/findTypingsPackages.d.mts +2 -2
- package/__compiled__/esm/src/tasks/buildTypesTask/findTypingsPackages.mjs.map +1 -1
- package/__compiled__/esm/src/tasks/gitignoreTask.d.mts +6 -0
- package/__compiled__/esm/src/tasks/gitignoreTask.mjs +14 -0
- package/__compiled__/esm/src/tasks/gitignoreTask.mjs.map +1 -0
- package/__compiled__/esm/src/writePackageJson.mjs +2 -33
- package/__compiled__/esm/src/writePackageJson.mjs.map +1 -1
- package/package.json +17 -11
@@ -3,18 +3,57 @@ const args = require("./args.js");
|
|
3
3
|
const _ = require("./index.js");
|
4
4
|
const PrettyErrors = require("./PrettyErrors.js");
|
5
5
|
const youch$1 = require("youch");
|
6
|
+
const parseMonorepo = require("./monorepo/parseMonorepo/parseMonorepo.js");
|
7
|
+
const buildAll = require("./monorepo/buildAll.js");
|
6
8
|
const youch = new youch$1.Youch();
|
7
9
|
(async () => {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
try {
|
11
|
+
const sourceDir = args.args.sourceDir || process.cwd();
|
12
|
+
const { monorepo, projectPaths } = await parseMonorepo.parseMonorepo({ sourceDir });
|
13
|
+
if (monorepo) {
|
14
|
+
if (projectPaths.length === 0) {
|
15
|
+
throw new PrettyErrors.PrettyError(
|
16
|
+
"No packages with -sbsources suffix found in monorepo"
|
17
|
+
);
|
18
|
+
}
|
19
|
+
const result = await buildAll.buildMonorepo({
|
20
|
+
...args.args,
|
21
|
+
monorepo
|
22
|
+
});
|
23
|
+
if (result.failedBuilds > 0) {
|
24
|
+
for (const { packagePath, errors } of result.errors) {
|
25
|
+
console.error(`
|
26
|
+
\x1B[31mErrors in ${packagePath}:\x1B[0m`);
|
27
|
+
for (const error of errors) {
|
28
|
+
if (!(error instanceof PrettyErrors.PrettyError)) {
|
29
|
+
console.error("\x1B[31m[ERROR]", error, "\x1B[0m");
|
30
|
+
continue;
|
31
|
+
}
|
32
|
+
console.error(await youch.toANSI(error));
|
33
|
+
}
|
34
|
+
}
|
35
|
+
process.exit(1);
|
36
|
+
}
|
37
|
+
return;
|
38
|
+
}
|
39
|
+
const res = await _.run(args.args);
|
40
|
+
if (!res.error) {
|
41
|
+
return;
|
42
|
+
}
|
43
|
+
for (const error of res.errors) {
|
44
|
+
if (!(error instanceof PrettyErrors.PrettyError)) {
|
45
|
+
console.error("\x1B[31m[ERROR]", error, "\x1B[0m");
|
46
|
+
continue;
|
47
|
+
}
|
48
|
+
console.error(await youch.toANSI(error));
|
49
|
+
}
|
50
|
+
} catch (error) {
|
51
|
+
if (error instanceof PrettyErrors.PrettyError) {
|
52
|
+
console.error(await youch.toANSI(error));
|
53
|
+
} else {
|
14
54
|
console.error("\x1B[31m[ERROR]", error, "\x1B[0m");
|
15
|
-
continue;
|
16
55
|
}
|
17
|
-
|
56
|
+
process.exit(1);
|
18
57
|
}
|
19
58
|
})();
|
20
59
|
//# sourceMappingURL=run.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"run.js","sources":["../../../../src/run.ts"],"sourcesContent":["import { args } from \"./args.js\";\nimport { run } from \"./index.js\";\nimport { PrettyError } from \"./PrettyErrors.js\";\nimport { Youch } from \"youch\";\n\nconst youch = new Youch();\n\n(async () => {\n const res = await run(args);\n\n
|
1
|
+
{"version":3,"file":"run.js","sources":["../../../../src/run.ts"],"sourcesContent":["import { args } from \"./args.js\";\nimport { run } from \"./index.js\";\nimport { PrettyError } from \"./PrettyErrors.js\";\nimport { Youch } from \"youch\";\nimport { parseMonorepo } from \"./monorepo/parseMonorepo/parseMonorepo.js\";\nimport { buildMonorepo } from \"./monorepo/buildAll.js\";\n\nconst youch = new Youch();\n\n(async () => {\n try {\n const sourceDir = args.sourceDir || process.cwd();\n\n // Check if we're in a monorepo\n const { monorepo, projectPaths } = await parseMonorepo({ sourceDir });\n\n if (monorepo) {\n // Handle monorepo build\n if (projectPaths.length === 0) {\n throw new PrettyError(\n \"No packages with -sbsources suffix found in monorepo\",\n );\n }\n\n const result = await buildMonorepo({\n ...args,\n monorepo,\n });\n\n // Print errors for failed packages\n if (result.failedBuilds > 0) {\n for (const { packagePath, errors } of result.errors) {\n console.error(`\\n\\x1b[31mErrors in ${packagePath}:\\x1b[0m`);\n for (const error of errors) {\n if (!(error instanceof PrettyError)) {\n console.error(\"\\x1b[31m[ERROR]\", error, \"\\x1b[0m\");\n continue;\n }\n console.error(await youch.toANSI(error));\n }\n }\n process.exit(1);\n }\n return;\n }\n\n // Not a monorepo, run normal build\n const res = await run(args);\n\n if (!res.error) {\n return;\n }\n\n for (const error of res.errors) {\n if (!(error instanceof PrettyError)) {\n console.error(\"\\x1b[31m[ERROR]\", error, \"\\x1b[0m\");\n continue;\n }\n\n console.error(await youch.toANSI(error));\n }\n } catch (error) {\n if (error instanceof PrettyError) {\n console.error(await youch.toANSI(error));\n } else {\n console.error(\"\\x1b[31m[ERROR]\", error, \"\\x1b[0m\");\n }\n process.exit(1);\n }\n})();\n"],"names":["Youch","args","parseMonorepo","PrettyError","buildMonorepo","run"],"mappings":";;;;;;;AAOA,MAAM,QAAQ,IAAIA,QAAAA,MAAM;AAAA,CAEvB,YAAY;AACP,MAAA;AACF,UAAM,YAAYC,KAAA,KAAK,aAAa,QAAQ,IAAI;AAG1C,UAAA,EAAE,UAAU,aAAa,IAAI,MAAMC,cAAc,cAAA,EAAE,WAAW;AAEpE,QAAI,UAAU;AAER,UAAA,aAAa,WAAW,GAAG;AAC7B,cAAM,IAAIC,aAAA;AAAA,UACR;AAAA,QACF;AAAA,MAAA;AAGI,YAAA,SAAS,MAAMC,uBAAc;AAAA,QACjC,GAAGH,KAAA;AAAA,QACH;AAAA,MAAA,CACD;AAGG,UAAA,OAAO,eAAe,GAAG;AAC3B,mBAAW,EAAE,aAAa,OAAO,KAAK,OAAO,QAAQ;AACnD,kBAAQ,MAAM;AAAA,oBAAuB,WAAW,UAAU;AAC1D,qBAAW,SAAS,QAAQ;AACtB,gBAAA,EAAE,iBAAiBE,aAAAA,cAAc;AAC3B,sBAAA,MAAM,mBAAmB,OAAO,SAAS;AACjD;AAAA,YAAA;AAEF,oBAAQ,MAAM,MAAM,MAAM,OAAO,KAAK,CAAC;AAAA,UAAA;AAAA,QACzC;AAEF,gBAAQ,KAAK,CAAC;AAAA,MAAA;AAEhB;AAAA,IAAA;AAII,UAAA,MAAM,MAAME,EAAA,IAAIJ,SAAI;AAEtB,QAAA,CAAC,IAAI,OAAO;AACd;AAAA,IAAA;AAGS,eAAA,SAAS,IAAI,QAAQ;AAC1B,UAAA,EAAE,iBAAiBE,aAAAA,cAAc;AAC3B,gBAAA,MAAM,mBAAmB,OAAO,SAAS;AACjD;AAAA,MAAA;AAGF,cAAQ,MAAM,MAAM,MAAM,OAAO,KAAK,CAAC;AAAA,IAAA;AAAA,WAElC,OAAO;AACd,QAAI,iBAAiBA,aAAAA,aAAa;AAChC,cAAQ,MAAM,MAAM,MAAM,OAAO,KAAK,CAAC;AAAA,IAAA,OAClC;AACG,cAAA,MAAM,mBAAmB,OAAO,SAAS;AAAA,IAAA;AAEnD,YAAQ,KAAK,CAAC;AAAA,EAAA;AAElB,GAAG;"}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { type PackageJson } from "../../packageJson.js";
|
2
|
-
import { type
|
2
|
+
import { type TSModule } from "../../detectModules.js";
|
3
3
|
import { type Dirs } from "../../resolveDirs.js";
|
4
4
|
type BuildTypesOptions = {
|
5
|
-
ts:
|
5
|
+
ts: TSModule;
|
6
6
|
dirs: Dirs;
|
7
7
|
packageJson: PackageJson;
|
8
8
|
tsEntrypoints: string[];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"callTypescript.js","sources":["../../../../../../src/tasks/buildTypesTask/callTypescript.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as fs from \"node:fs\";\nimport {\n inlineExtensionsMjs,\n inlineExtensionsCjs,\n} from \"./inlineExtensions.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { getMinVersion, type
|
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 TSModule } 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: TSModule;\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 // we create maps for ts and tsx because it can have any of these extensions\n // I don't want to detect the original ext,\n // so I've decided just create two maps and calculate the original file name outside of this function\n const sourceFileNameTS = fileName.replace(/\\.d\\.ts$/, \".ts\"); // Assuming source files have .ts extension\n const sourceFileNameTSX = fileName.replace(/\\.d\\.ts$/, \".tsx\"); // 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(sourceFileNameTS, esmFinalPath);\n sourceToEsmDtsMap.set(sourceFileNameTSX, 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(sourceFileNameTS, cjsFinalPath);\n sourceToCjsDtsMap.set(sourceFileNameTSX, cjsFinalPath);\n });\n // </build d.ts>\n\n // <fix vscode typings>\n for (const file of [\n ...sourceToCjsDtsMap.values(),\n ...sourceToEsmDtsMap.values(),\n ]) {\n const content = fs.readFileSync(file, \"utf-8\");\n const relativePath = path.relative(outDir, file);\n if (file.endsWith(\".d.ts\")) {\n const transformedCode = inlineExtensionsCjs(\n ts.ts,\n content,\n makeFileExists(outDir, relativePath),\n );\n fs.writeFileSync(file, transformedCode);\n }\n if (file.endsWith(\".d.mts\")) {\n const transformedCode = inlineExtensionsMjs(\n ts.ts,\n content,\n makeFileExists(outDir, relativePath),\n );\n fs.writeFileSync(file, transformedCode);\n }\n }\n // </fix vscode typings>\n\n // <find all libraries names>\n const packages = new Set<string>();\n for (const sourceEntrypoint of tsEntrypoints) {\n const esmEntrypoint = sourceToEsmDtsMap.get(sourceEntrypoint);\n if (esmEntrypoint) {\n const localPackages = findTypingsNames(\n ts,\n esmEntrypoint,\n esmOutDir,\n \".d.mts\",\n );\n for (const p of localPackages) {\n packages.add(p);\n }\n }\n\n const cjsEntrypoint = sourceToCjsDtsMap.get(sourceEntrypoint);\n if (cjsEntrypoint) {\n const localPackages = findTypingsNames(\n ts,\n cjsEntrypoint,\n cjsOutDir,\n \".d.ts\",\n );\n for (const p of localPackages) {\n packages.add(p);\n }\n }\n }\n // </find all libraries names>\n\n // <check not installed typings libraries>\n const { missingTypings, existingTypingPackages } = findTypingsPackages(\n ts,\n packages,\n sourceDir,\n );\n for (const lib of existingTypingPackages) {\n if (\n getMinVersion(packageJson, lib, [\n \"optionalDependencies\",\n \"devDependencies\",\n ]) == null\n ) {\n missingTypings.add(lib);\n }\n }\n if (missingTypings.size > 0) {\n const libsList = [...missingTypings].map((x) => `\"${x}\"`).join(\", \");\n throw new BuildError(\n `The typings won't installed in bundled package: ${libsList}. Please install them into dependencies or peerDependencies.`,\n );\n }\n // </check not installed typings libraries>\n\n return {\n sourceToCjsDtsMap,\n sourceToEsmDtsMap,\n };\n}\n"],"names":["path","fs","inlineExtensionsCjs","inlineExtensionsMjs","findTypingsNames","findTypingsPackages","getMinVersion","BuildError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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IAAI,GAAG;AAAA,IAAA;AAAA,EACxB;AAEE,MAAA,eAAe,OAAO,GAAG;AAC3B,UAAM,WAAW,CAAC,GAAG,cAAc,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,GAAG,EAAE,KAAK,IAAI;AACnE,UAAM,IAAIC,MAAA;AAAA,MACR,mDAAmD,QAAQ;AAAA,IAC7D;AAAA,EAAA;AAIK,SAAA;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;;"}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import type {
|
2
|
-
export declare function findTypingsNames({ ts }:
|
1
|
+
import type { TSModule } from "../../detectModules.js";
|
2
|
+
export declare function findTypingsNames({ ts }: TSModule, entrypoint: string, sourceDir: string, ext: string): Set<string>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"findTypingsNames.js","sources":["../../../../../../src/tasks/buildTypesTask/findTypingsNames.ts"],"sourcesContent":["import type * as ts from \"typescript\";\nimport { join, relative } from \"node:path\";\nimport { readdirSync, statSync } from \"node:fs\";\nimport type {
|
1
|
+
{"version":3,"file":"findTypingsNames.js","sources":["../../../../../../src/tasks/buildTypesTask/findTypingsNames.ts"],"sourcesContent":["import type * as ts from \"typescript\";\nimport { join, relative } from \"node:path\";\nimport { readdirSync, statSync } from \"node:fs\";\nimport type { TSModule } from \"../../detectModules.js\";\n\nfunction createCompilerHostWithVirtualSource(ts: TSModule[\"ts\"], sourceDir: string) {\n return ts.createCompilerHost({\n target: ts.ScriptTarget.ESNext,\n moduleResolution: ts.ModuleResolutionKind.NodeNext,\n baseUrl: \".\",\n sourceRoot: sourceDir,\n noEmit: true,\n emitDeclarationOnly: true,\n noEmitOnError: true,\n });\n}\n\n/*\nChatGPT told me we need to specify all files in rootNames for the program to work correctly.\n */\nfunction collectAllFilesInDir(sourceDir: string, ext: string) {\n const files = readdirSync(sourceDir);\n const ret = new Array<string>();\n for (const file of files) {\n // check if the file is a directory\n const stat = statSync(join(sourceDir, file));\n if (stat.isDirectory()) {\n ret.push(...collectAllFilesInDir(join(sourceDir, file), ext));\n } else if (file.endsWith(ext)) {\n ret.push(join(sourceDir, file));\n }\n }\n\n return ret;\n}\n\nexport function findTypingsNames(\n { ts }: TSModule,\n entrypoint: string,\n sourceDir: string,\n ext: string,\n) {\n const host = createCompilerHostWithVirtualSource(ts, sourceDir);\n const program = ts.createProgram({\n rootNames: collectAllFilesInDir(sourceDir, ext),\n options: {},\n host,\n });\n\n const packages = new Set<string>();\n const processedFiles = new Set<string>();\n const filesQueue = [relative(sourceDir, entrypoint)];\n\n function processModuleSpecifier(moduleSpecifier: ts.StringLiteral) {\n const moduleName = moduleSpecifier.text;\n if (moduleName.startsWith(\".\")) {\n filesQueue.push(moduleName.replace(/\\.js$/, ext));\n return;\n }\n\n packages.add(moduleName);\n }\n\n while (filesQueue.length > 0) {\n const relativeCurrentFile = filesQueue.pop()!;\n const currentFile = join(sourceDir, relativeCurrentFile);\n if (processedFiles.has(currentFile)) continue;\n\n const sourceFile = program.getSourceFile(currentFile);\n if (!sourceFile) continue;\n\n function visit(node: ts.Node) {\n // import \"moduleSpecifier\";\n if (\n ts.isImportDeclaration(node) &&\n ts.isStringLiteral(node.moduleSpecifier)\n ) {\n processModuleSpecifier(node.moduleSpecifier);\n }\n\n // Generic<import(\"node\")>;\n if (\n ts.isImportTypeNode(node) &&\n ts.isLiteralTypeNode(node.argument) &&\n ts.isStringLiteral(node.argument.literal)\n ) {\n processModuleSpecifier(node.argument.literal);\n }\n\n // export * from \"moduleSpecifier\";\n if (\n ts.isExportDeclaration(node) &&\n node.moduleSpecifier &&\n ts.isStringLiteral(node.moduleSpecifier)\n ) {\n processModuleSpecifier(node.moduleSpecifier);\n }\n\n ts.forEachChild(node, visit);\n }\n\n processedFiles.add(currentFile);\n\n ts.forEachChild(sourceFile, visit);\n }\n\n return packages;\n}\n"],"names":["readdirSync","statSync","join","relative"],"mappings":";;;;AAKA,SAAS,oCAAoC,IAAoB,WAAmB;AAClF,SAAO,GAAG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,GAAG,gBAAgB,KAAK,eAAe,GACvC;AACA,+BAAuB,KAAK,eAAe;AAAA,MAAA;AAI7C,UACE,GAAG,iBAAiB,IAAI,KACxB,GAAG,kBAAkB,KAAK,QAAQ,KAClC,GAAG,gBAAgB,KAAK,SAAS,OAAO,GACxC;AACuB,+BAAA,KAAK,SAAS,OAAO;AAAA,MAAA;AAK5C,UAAA,GAAG,oBAAoB,IAAI,KAC3B,KAAK,mBACL,GAAG,gBAAgB,KAAK,eAAe,GACvC;AACA,+BAAuB,KAAK,eAAe;AAAA,MAAA;AAG1C,SAAA,aAAa,MAAM,KAAK;AAAA,IAC7B;AAnCM,UAAA,sBAAsB,WAAW,IAAI;AACrC,UAAA,cAAcD,KAAAA,KAAK,WAAW,mBAAmB;AACnD,QAAA,eAAe,IAAI,WAAW,EAAG;AAE/B,UAAA,aAAa,QAAQ,cAAc,WAAW;AACpD,QAAI,CAAC,WAAY;AAgCjB,mBAAe,IAAI,WAAW;AAE3B,OAAA,aAAa,YAAY,KAAK;AAAA,EAAA;AAG5B,SAAA;AACT;;"}
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import type {
|
2
|
-
export declare function findTypingsPackages({ ts }:
|
1
|
+
import type { TSModule } from "../../detectModules.js";
|
2
|
+
export declare function findTypingsPackages({ ts }: TSModule, packages: Set<string>, sourceDir: string): {
|
3
3
|
missingTypings: Set<string>;
|
4
4
|
existingTypingPackages: Set<string>;
|
5
5
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"findTypingsPackages.js","sources":["../../../../../../src/tasks/buildTypesTask/findTypingsPackages.ts"],"sourcesContent":["import type * as ts from \"typescript\";\nimport * as path from \"node:path\";\nimport type {
|
1
|
+
{"version":3,"file":"findTypingsPackages.js","sources":["../../../../../../src/tasks/buildTypesTask/findTypingsPackages.ts"],"sourcesContent":["import type * as ts from \"typescript\";\nimport * as path from \"node:path\";\nimport type { TSModule } from \"../../detectModules.js\";\n\ntype HostFunctions = {\n getSourceFile: ts.CompilerHost[\"getSourceFile\"];\n fileExists: ts.CompilerHost[\"fileExists\"];\n readFile: ts.CompilerHost[\"readFile\"];\n};\n\nfunction createVirtualHostFunctions(\n ts: TSModule[\"ts\"],\n virtualFilePath: string,\n virtualSourceContent: string,\n originalHost: ts.CompilerHost,\n): HostFunctions {\n const getSourceFile: ts.CompilerHost[\"getSourceFile\"] = (\n fileName,\n languageVersion,\n ) => {\n if (fileName === virtualFilePath) {\n return ts.createSourceFile(\n fileName,\n virtualSourceContent,\n languageVersion,\n );\n }\n return originalHost.getSourceFile(fileName, languageVersion);\n };\n\n const fileExists: ts.CompilerHost[\"fileExists\"] = (fileName) => {\n if (fileName === virtualFilePath) {\n return true;\n }\n return originalHost.fileExists(fileName);\n };\n\n const readFile: ts.CompilerHost[\"readFile\"] = (fileName) => {\n if (fileName === virtualFilePath) {\n return virtualSourceContent;\n }\n return originalHost.readFile(fileName);\n };\n\n return {\n getSourceFile,\n fileExists,\n readFile,\n };\n}\n\nfunction createCompilerHostWithVirtualSource(\n ts: TSModule[\"ts\"],\n packages: Set<string>,\n sourceDir: string,\n) {\n const virtualSourceContent =\n [...packages].map((p) => `import \"${p}\";`).join(\"\\n\") +\n // for ignoring the `Generated an empty chunk: \".\"` error\n \"export const a = 1;\\n\";\n const virtualFilePath = path.join(sourceDir, \"virtual.ts\");\n\n const originalHost = ts.createCompilerHost({\n target: ts.ScriptTarget.ESNext,\n moduleResolution: ts.ModuleResolutionKind.NodeNext,\n baseUrl: \".\",\n sourceRoot: sourceDir,\n noEmit: true,\n emitDeclarationOnly: true,\n noEmitOnError: true,\n paths: {\n \"*\": [\"node_modules/*\"],\n },\n });\n const virtualFunctions = createVirtualHostFunctions(\n ts,\n virtualFilePath,\n virtualSourceContent,\n originalHost,\n );\n\n return {\n host: new Proxy(originalHost, {\n get(target, prop: keyof ts.CompilerHost) {\n return virtualFunctions[prop as keyof HostFunctions] || target[prop];\n },\n }),\n virtualFilePath,\n };\n}\n\nexport function findTypingsPackages(\n { ts }: TSModule,\n packages: Set<string>,\n sourceDir: string,\n) {\n const { host, virtualFilePath } = createCompilerHostWithVirtualSource(\n ts,\n packages,\n sourceDir,\n );\n\n const program = ts.createProgram({\n rootNames: [virtualFilePath],\n options: {},\n host: host,\n });\n\n const sourceFile = program.getSourceFile(virtualFilePath);\n if (!sourceFile) {\n throw new Error(\n \"[getSourceFile] Impossible error inside findMissingTypings\",\n );\n }\n\n const missingTypings = new Set<string>();\n const existingTypingPackages = new Set<string>();\n sourceFile.forEachChild((node) => {\n if (ts.isImportDeclaration(node)) {\n const moduleSpecifier = node.moduleSpecifier;\n if (ts.isStringLiteral(moduleSpecifier)) {\n const moduleResolution = ts.resolveModuleName(\n moduleSpecifier.text,\n virtualFilePath,\n {},\n host,\n );\n\n if (!moduleResolution?.resolvedModule?.packageId) {\n missingTypings.add(moduleSpecifier.text);\n } else {\n existingTypingPackages.add(\n moduleResolution.resolvedModule.packageId.name,\n );\n }\n }\n }\n });\n\n return { missingTypings, existingTypingPackages };\n}\n"],"names":["path"],"mappings":";;;;;;;;;;;;;;;;;;;;AAUA,SAAS,2BACP,IACA,iBACA,sBACA,cACe;AACT,QAAA,gBAAkD,CACtD,UACA,oBACG;AACH,QAAI,aAAa,iBAAiB;AAChC,aAAO,GAAG;AAAA,QACR;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IAAA;AAEK,WAAA,aAAa,cAAc,UAAU,eAAe;AAAA,EAC7D;AAEM,QAAA,aAA4C,CAAC,aAAa;AAC9D,QAAI,aAAa,iBAAiB;AACzB,aAAA;AAAA,IAAA;AAEF,WAAA,aAAa,WAAW,QAAQ;AAAA,EACzC;AAEM,QAAA,WAAwC,CAAC,aAAa;AAC1D,QAAI,aAAa,iBAAiB;AACzB,aAAA;AAAA,IAAA;AAEF,WAAA,aAAa,SAAS,QAAQ;AAAA,EACvC;AAEO,SAAA;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,SAAS,oCACP,IAC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vC,cAAM,mBAAmB,GAAG;AAAA,UAC1B,gBAAgB;AAAA,UAChB;AAAA,UACA,CAAC;AAAA,UACD;AAAA,QACF;AAEI,YAAA,GAAC,0DAAkB,mBAAlB,mBAAkC,YAAW;AACjC,yBAAA,IAAI,gBAAgB,IAAI;AAAA,QAAA,OAClC;AACkB,iCAAA;AAAA,YACrB,iBAAiB,eAAe,UAAU;AAAA,UAC5C;AAAA,QAAA;AAAA,MACF;AAAA,IACF;AAAA,EACF,CACD;AAEM,SAAA,EAAE,gBAAgB,uBAAuB;AAClD;;"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
+
const fs = require("node:fs/promises");
|
4
|
+
const path = require("node:path");
|
5
|
+
async function gitignoreTask({ dirs }) {
|
6
|
+
const { outDir } = dirs;
|
7
|
+
const gitignoreContent = "*\n";
|
8
|
+
const gitignorePath = path.join(outDir, ".gitignore");
|
9
|
+
await fs.writeFile(gitignorePath, gitignoreContent);
|
10
|
+
const npmignorePath = path.join(outDir, ".npmignore");
|
11
|
+
await fs.writeFile(npmignorePath, "");
|
12
|
+
}
|
13
|
+
exports.gitignoreTask = gitignoreTask;
|
14
|
+
//# sourceMappingURL=gitignoreTask.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"gitignoreTask.js","sources":["../../../../../src/tasks/gitignoreTask.ts"],"sourcesContent":["import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { Dirs } from \"../resolveDirs.js\";\n\ntype GitignoreTaskArg = {\n dirs: Dirs;\n};\n\nexport async function gitignoreTask({ dirs }: GitignoreTaskArg) {\n const { outDir } = dirs;\n\n // Ignore the all files to prevent commiting the dist\n const gitignoreContent = \"*\\n\";\n\n const gitignorePath = path.join(outDir, \".gitignore\");\n await fs.writeFile(gitignorePath, gitignoreContent);\n\n // We need to have empty .npmignore to avoid reading .gitignore in pnpm publishing\n const npmignorePath = path.join(outDir, \".npmignore\");\n await fs.writeFile(npmignorePath, \"\");\n}\n"],"names":[],"mappings":";;;;AAQsB,eAAA,cAAc,EAAE,QAA0B;AACxD,QAAA,EAAE,WAAW;AAGnB,QAAM,mBAAmB;AAEzB,QAAM,gBAAgB,KAAK,KAAK,QAAQ,YAAY;AAC9C,QAAA,GAAG,UAAU,eAAe,gBAAgB;AAGlD,QAAM,gBAAgB,KAAK,KAAK,QAAQ,YAAY;AAC9C,QAAA,GAAG,UAAU,eAAe,EAAE;AACtC;;"}
|
@@ -4,6 +4,7 @@ const fs = require("node:fs/promises");
|
|
4
4
|
require("zod");
|
5
5
|
require("node:path");
|
6
6
|
const log = require("./log.js");
|
7
|
+
const convertPackageJson = require("./monorepo/convertPackageJson.js");
|
7
8
|
function extractValue(value) {
|
8
9
|
if (!value) {
|
9
10
|
return void 0;
|
@@ -13,28 +14,6 @@ function extractValue(value) {
|
|
13
14
|
}
|
14
15
|
return value.default;
|
15
16
|
}
|
16
|
-
const monorepoPostfix = "-sbsources";
|
17
|
-
const monorepoPostfixRegex = new RegExp(`${monorepoPostfix}$`);
|
18
|
-
function walkOverMonorepoDepsToRemovePostfix(deps) {
|
19
|
-
if (!deps) {
|
20
|
-
return void 0;
|
21
|
-
}
|
22
|
-
const res = {};
|
23
|
-
for (const [key, value] of Object.entries(deps)) {
|
24
|
-
if (key.endsWith(monorepoPostfix)) {
|
25
|
-
res[key.replace(monorepoPostfixRegex, "")] = value;
|
26
|
-
} else {
|
27
|
-
res[key] = value;
|
28
|
-
}
|
29
|
-
}
|
30
|
-
return res;
|
31
|
-
}
|
32
|
-
const allDepsClauses = [
|
33
|
-
"dependencies",
|
34
|
-
"optionalDependencies",
|
35
|
-
"peerDependencies",
|
36
|
-
"devDependencies"
|
37
|
-
];
|
38
17
|
async function writePackageJson(outDir, parsed, { exportsMap, binsMap }) {
|
39
18
|
const allExports = {};
|
40
19
|
for (const [key, value] of exportsMap) {
|
@@ -60,17 +39,7 @@ async function writePackageJson(outDir, parsed, { exportsMap, binsMap }) {
|
|
60
39
|
allExports["./package.json"] = "./package.json";
|
61
40
|
const bin = binsMap.size > 0 ? Object.fromEntries(binsMap) : void 0;
|
62
41
|
const rootExport = typeof allExports["."] === "object" ? allExports["."] : void 0;
|
63
|
-
|
64
|
-
const originalName = parsed.name;
|
65
|
-
parsed.name = parsed.name.replace(monorepoPostfix, "");
|
66
|
-
for (const depClause of allDepsClauses) {
|
67
|
-
parsed[depClause] = walkOverMonorepoDepsToRemovePostfix(
|
68
|
-
parsed[depClause]
|
69
|
-
);
|
70
|
-
}
|
71
|
-
parsed.devDependencies = parsed.devDependencies ?? {};
|
72
|
-
parsed.devDependencies[originalName] = "*";
|
73
|
-
}
|
42
|
+
parsed = convertPackageJson.convertPackageJson(parsed);
|
74
43
|
const res = {
|
75
44
|
name: parsed.name,
|
76
45
|
type: "commonjs",
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"writePackageJson.js","sources":["../../../../src/writePackageJson.ts"],"sourcesContent":["import { writeFile } from \"node:fs/promises\";\nimport { type PackageJson } from \"./packageJson.js\";\nimport { okLog } from \"./log.js\";\n\nexport type ExportsObject = {\n mjs?: string;\n dmts?: string;\n dcts?: string;\n cjs?: string;\n raw?: string;\n};\n\ntype BuildResult = {\n exportsMap: Map<string, ExportsObject>;\n binsMap: Map<string, string>;\n};\n\ntype ExportsPackageJsonObj =\n | {\n import?: ExportsPackageJsonObj;\n require?: ExportsPackageJsonObj;\n types?: string;\n default?: string;\n }\n | string;\n\nfunction extractValue(value?: ExportsPackageJsonObj) {\n if (!value) {\n return undefined;\n }\n if (typeof value === \"string\") {\n return value;\n }\n return value.default;\n}\n\
|
1
|
+
{"version":3,"file":"writePackageJson.js","sources":["../../../../src/writePackageJson.ts"],"sourcesContent":["import { writeFile } from \"node:fs/promises\";\nimport { type PackageJson } from \"./packageJson.js\";\nimport { okLog } from \"./log.js\";\nimport { convertPackageJson } from \"./monorepo/convertPackageJson.js\";\n\nexport type ExportsObject = {\n mjs?: string;\n dmts?: string;\n dcts?: string;\n cjs?: string;\n raw?: string;\n};\n\ntype BuildResult = {\n exportsMap: Map<string, ExportsObject>;\n binsMap: Map<string, string>;\n};\n\ntype ExportsPackageJsonObj =\n | {\n import?: ExportsPackageJsonObj;\n require?: ExportsPackageJsonObj;\n types?: string;\n default?: string;\n }\n | string;\n\nfunction extractValue(value?: ExportsPackageJsonObj) {\n if (!value) {\n return undefined;\n }\n if (typeof value === \"string\") {\n return value;\n }\n return value.default;\n}\n\nexport async function writePackageJson(\n outDir: string,\n parsed: PackageJson,\n { exportsMap, binsMap }: BuildResult,\n) {\n // we always want to have `exports` property in the target package.json\n // If you want to export something, please, specify them\n const allExports: Record<string, ExportsPackageJsonObj> = {};\n for (const [key, value] of exportsMap) {\n const anExport: ExportsPackageJsonObj = {};\n\n if (value.mjs) {\n anExport.import = {};\n if (value.dmts) {\n anExport.import.types = value.dmts;\n }\n anExport.import.default = value.mjs;\n }\n if (value.cjs) {\n anExport.require = {};\n if (value.dcts) {\n anExport.require.types = value.dcts;\n }\n anExport.require.default = value.cjs;\n }\n\n // should be first for correct resolving\n anExport.types = value.dcts ?? value.dmts;\n // because we need to have default and types key on the end\n // JSON.stringify will put it on the end if we put value at the last step\n anExport.default = value.cjs;\n\n allExports[key] = anExport;\n }\n allExports[\"./package.json\"] = \"./package.json\";\n\n const bin = binsMap.size > 0 ? Object.fromEntries(binsMap) : undefined;\n\n const rootExport =\n typeof allExports[\".\"] === \"object\" ? allExports[\".\"] : undefined;\n\n parsed = convertPackageJson(parsed);\n\n const res = {\n name: parsed.name,\n type: \"commonjs\",\n version: parsed.version,\n bin,\n types: rootExport?.types,\n module: extractValue(rootExport?.import),\n main: extractValue(rootExport?.require),\n description: parsed.description ?? \"\",\n exports: allExports,\n dependencies: parsed.dependencies ?? undefined,\n optionalDependencies: parsed.optionalDependencies ?? undefined,\n repository: parsed.repository,\n keywords: parsed.keywords,\n author: parsed.author,\n contributors: parsed.contributors,\n license: parsed.license,\n peerDependencies: parsed.peerDependencies,\n engines: parsed.engines,\n browser: parsed.browser,\n funding: parsed.funding,\n os: parsed.os,\n cpu: parsed.cpu,\n maintainers: parsed.maintainers,\n bugs: parsed.bugs,\n sideEffects: parsed.sideEffects,\n unpkg: parsed.unpkg,\n homepage: parsed.homepage,\n devDependencies: parsed.devDependencies,\n peerDependenciesMeta: parsed.peerDependenciesMeta,\n };\n\n await writeFile(`${outDir}/package.json`, JSON.stringify(res, null, 2));\n\n okLog(\"package.json\");\n}\n"],"names":["convertPackageJson","writeFile","okLog"],"mappings":";;;;;;;AA2BA,SAAS,aAAa,OAA+B;AACnD,MAAI,CAAC,OAAO;AACH,WAAA;AAAA,EAAA;AAEL,MAAA,OAAO,UAAU,UAAU;AACtB,WAAA;AAAA,EAAA;AAET,SAAO,MAAM;AACf;AAEA,eAAsB,iBACpB,QACA,QACA,EAAE,YAAY,WACd;AAGA,QAAM,aAAoD,CAAC;AAC3D,aAAW,CAAC,KAAK,KAAK,KAAK,YAAY;AACrC,UAAM,WAAkC,CAAC;AAEzC,QAAI,MAAM,KAAK;AACb,eAAS,SAAS,CAAC;AACnB,UAAI,MAAM,MAAM;AACL,iBAAA,OAAO,QAAQ,MAAM;AAAA,MAAA;AAEvB,eAAA,OAAO,UAAU,MAAM;AAAA,IAAA;AAElC,QAAI,MAAM,KAAK;AACb,eAAS,UAAU,CAAC;AACpB,UAAI,MAAM,MAAM;AACL,iBAAA,QAAQ,QAAQ,MAAM;AAAA,MAAA;AAExB,eAAA,QAAQ,UAAU,MAAM;AAAA,IAAA;AAI1B,aAAA,QAAQ,MAAM,QAAQ,MAAM;AAGrC,aAAS,UAAU,MAAM;AAEzB,eAAW,GAAG,IAAI;AAAA,EAAA;AAEpB,aAAW,gBAAgB,IAAI;AAE/B,QAAM,MAAM,QAAQ,OAAO,IAAI,OAAO,YAAY,OAAO,IAAI;AAEvD,QAAA,aACJ,OAAO,WAAW,GAAG,MAAM,WAAW,WAAW,GAAG,IAAI;AAE1D,WAASA,sCAAmB,MAAM;AAElC,QAAM,MAAM;AAAA,IACV,MAAM,OAAO;AAAA,IACb,MAAM;AAAA,IACN,SAAS,OAAO;AAAA,IAChB;AAAA,IACA,OAAO,yCAAY;AAAA,IACnB,QAAQ,aAAa,yCAAY,MAAM;AAAA,IACvC,MAAM,aAAa,yCAAY,OAAO;AAAA,IACtC,aAAa,OAAO,eAAe;AAAA,IACnC,SAAS;AAAA,IACT,cAAc,OAAO,gBAAgB;AAAA,IACrC,sBAAsB,OAAO,wBAAwB;AAAA,IACrD,YAAY,OAAO;AAAA,IACnB,UAAU,OAAO;AAAA,IACjB,QAAQ,OAAO;AAAA,IACf,cAAc,OAAO;AAAA,IACrB,SAAS,OAAO;AAAA,IAChB,kBAAkB,OAAO;AAAA,IACzB,SAAS,OAAO;AAAA,IAChB,SAAS,OAAO;AAAA,IAChB,SAAS,OAAO;AAAA,IAChB,IAAI,OAAO;AAAA,IACX,KAAK,OAAO;AAAA,IACZ,aAAa,OAAO;AAAA,IACpB,MAAM,OAAO;AAAA,IACb,aAAa,OAAO;AAAA,IACpB,OAAO,OAAO;AAAA,IACd,UAAU,OAAO;AAAA,IACjB,iBAAiB,OAAO;AAAA,IACxB,sBAAsB,OAAO;AAAA,EAC/B;AAEM,QAAAC,aAAU,GAAG,MAAM,iBAAiB,KAAK,UAAU,KAAK,MAAM,CAAC,CAAC;AAEtEC,MAAAA,MAAM,cAAc;AACtB;;"}
|
@@ -4,6 +4,7 @@ export declare const args: {
|
|
4
4
|
packagePath: string;
|
5
5
|
outputDir: string;
|
6
6
|
seq: boolean;
|
7
|
+
ci: boolean;
|
7
8
|
_: (string | number)[];
|
8
9
|
$0: string;
|
9
10
|
};
|
@@ -15,5 +16,12 @@ type ConvertUndefinedToOptional<T> = {
|
|
15
16
|
} & {
|
16
17
|
[K in keyof T as undefined extends T[K] ? never : K]: T[K];
|
17
18
|
};
|
18
|
-
export type
|
19
|
+
export type Monorepo = {
|
20
|
+
type: "pnpm";
|
21
|
+
devDeps: Record<string, string>;
|
22
|
+
};
|
23
|
+
export type Args = ConvertUndefinedToOptional<Omit<OmitUnknown<typeof args>, "_" | "$0">> & {
|
24
|
+
monorepo?: Monorepo;
|
25
|
+
skipGitignore?: boolean;
|
26
|
+
};
|
19
27
|
export {};
|
@@ -16,6 +16,9 @@ const argsSchema = yargs().option("sourceDir", {
|
|
16
16
|
}).option("seq", {
|
17
17
|
type: "boolean",
|
18
18
|
describe: "run internal tasks sequentially. It is useful for performance testing and debugging. This option is unstable and not recommended for production use."
|
19
|
+
}).option("ci", {
|
20
|
+
type: "boolean",
|
21
|
+
describe: "run in CI mode"
|
19
22
|
}).help("help");
|
20
23
|
const args = argsSchema.parseSync(hideBin(process.argv));
|
21
24
|
export {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"args.mjs","sources":["../../../../src/args.ts"],"sourcesContent":["import yargs from \"yargs\";\nimport * as process from \"node:process\";\nimport { hideBin } from \"yargs/helpers\";\n\nconst argsSchema = yargs()\n .option(\"sourceDir\", {\n alias: \"s\",\n type: \"string\",\n describe:\n \"path to the project directory. Default: current working directory\",\n })\n .option(\"packagePath\", {\n alias: \"p\",\n type: \"string\",\n describe: \"path to the package.json. Default: cwd()/package.json\",\n })\n .option(\"outputDir\", {\n alias: \"o\",\n type: \"string\",\n describe: \"path to the output directory. Default: cwd()/dist\",\n })\n // Do not cover this option in tests because it is unstable\n .option(\"seq\", {\n type: \"boolean\",\n describe:\n \"run internal tasks sequentially. It is useful for performance testing and debugging. This option is unstable and not recommended for production use.\",\n })\n .help(\"help\");\n\nexport const args = argsSchema.parseSync(hideBin(process.argv));\n\ntype OmitUnknown<T> = {\n [K in keyof T as string extends K ? never : K]: T[K];\n};\ntype ConvertUndefinedToOptional<T> = {\n [K in keyof T as undefined extends T[K] ? K : never]?: Exclude<\n T[K],\n undefined\n >;\n} & {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K];\n};\n\nexport type Args = ConvertUndefinedToOptional<\n Omit<OmitUnknown<typeof args>, \"_\" | \"$0\">\n
|
1
|
+
{"version":3,"file":"args.mjs","sources":["../../../../src/args.ts"],"sourcesContent":["import yargs from \"yargs\";\nimport * as process from \"node:process\";\nimport { hideBin } from \"yargs/helpers\";\n\nconst argsSchema = yargs()\n .option(\"sourceDir\", {\n alias: \"s\",\n type: \"string\",\n describe:\n \"path to the project directory. Default: current working directory\",\n })\n .option(\"packagePath\", {\n alias: \"p\",\n type: \"string\",\n describe: \"path to the package.json. Default: cwd()/package.json\",\n })\n .option(\"outputDir\", {\n alias: \"o\",\n type: \"string\",\n describe: \"path to the output directory. Default: cwd()/dist\",\n })\n // Do not cover this option in tests because it is unstable\n .option(\"seq\", {\n type: \"boolean\",\n describe:\n \"run internal tasks sequentially. It is useful for performance testing and debugging. This option is unstable and not recommended for production use.\",\n })\n .option(\"ci\", {\n type: \"boolean\",\n describe: \"run in CI mode\",\n })\n .help(\"help\");\n\nexport const args = argsSchema.parseSync(hideBin(process.argv));\n\ntype OmitUnknown<T> = {\n [K in keyof T as string extends K ? never : K]: T[K];\n};\ntype ConvertUndefinedToOptional<T> = {\n [K in keyof T as undefined extends T[K] ? K : never]?: Exclude<\n T[K],\n undefined\n >;\n} & {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K];\n};\n\nexport type Monorepo = {\n type: \"pnpm\";\n devDeps: Record<string, string>;\n};\n\nexport type Args = ConvertUndefinedToOptional<\n Omit<OmitUnknown<typeof args>, \"_\" | \"$0\">\n> & {\n monorepo?: Monorepo;\n skipGitignore?: boolean;\n};\n"],"names":[],"mappings":";;;AAIA,MAAM,aAAa,MAAA,EAChB,OAAO,aAAa;AAAA,EACnB,OAAO;AAAA,EACP,MAAM;AAAA,EACN,UACE;AACJ,CAAC,EACA,OAAO,eAAe;AAAA,EACrB,OAAO;AAAA,EACP,MAAM;AAAA,EACN,UAAU;AACZ,CAAC,EACA,OAAO,aAAa;AAAA,EACnB,OAAO;AAAA,EACP,MAAM;AAAA,EACN,UAAU;AACZ,CAAC,EAEA,OAAO,OAAO;AAAA,EACb,MAAM;AAAA,EACN,UACE;AACJ,CAAC,EACA,OAAO,MAAM;AAAA,EACZ,MAAM;AAAA,EACN,UAAU;AACZ,CAAC,EACA,KAAK,MAAM;AAEP,MAAM,OAAO,WAAW,UAAU,QAAQ,QAAQ,IAAI,CAAC;"}
|
@@ -1,23 +1,37 @@
|
|
1
1
|
import { type PackageJson } from "./packageJson.js";
|
2
2
|
import semver from "semver";
|
3
3
|
import type { Dirs } from "./resolveDirs.js";
|
4
|
-
|
4
|
+
import type { Monorepo } from "./args.js";
|
5
|
+
type ModuleWithVersion<T> = T & {
|
6
|
+
version: string;
|
7
|
+
};
|
8
|
+
type TSModuleData = {
|
5
9
|
ts: typeof import("typescript");
|
6
10
|
parsedConfig: import("typescript").ParsedCommandLine;
|
7
11
|
host: import("typescript").CompilerHost;
|
8
12
|
};
|
13
|
+
type BabelModuleData = {
|
14
|
+
babel: typeof import("@babel/core");
|
15
|
+
};
|
16
|
+
type ReactModuleData = {
|
17
|
+
transform: "legacy" | "modern";
|
18
|
+
};
|
19
|
+
export type TSModule = ModuleWithVersion<TSModuleData>;
|
20
|
+
export type BabelModule = ModuleWithVersion<BabelModuleData>;
|
21
|
+
export type ReactModule = ModuleWithVersion<ReactModuleData>;
|
9
22
|
export type DetectedModules = {
|
10
|
-
ts?:
|
11
|
-
babel?:
|
12
|
-
react?:
|
23
|
+
ts?: TSModule;
|
24
|
+
babel?: BabelModule;
|
25
|
+
react?: ReactModule;
|
13
26
|
};
|
14
|
-
type
|
15
|
-
|
16
|
-
export declare function detectModules(packageJson: PackageJson, dirs: Dirs): Promise<{
|
17
|
-
error: false;
|
27
|
+
export type DetectModulesResult = {
|
28
|
+
success: true;
|
18
29
|
modules: DetectedModules;
|
19
30
|
} | {
|
20
|
-
|
21
|
-
errors:
|
22
|
-
}
|
31
|
+
success: false;
|
32
|
+
errors: string[];
|
33
|
+
};
|
34
|
+
type DepType = "dependencies" | "devDependencies" | "peerDependencies" | "optionalDependencies";
|
35
|
+
export declare function getMinVersion(packageJson: PackageJson, depName: string, exclude: DepType[]): semver.SemVer | null;
|
36
|
+
export declare function detectModules(packageJson: PackageJson, dirs: Dirs, monorepo?: Monorepo): Promise<DetectModulesResult>;
|
23
37
|
export {};
|