@sanity/pkg-utils 7.4.0 → 7.4.1-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks-cjs/findConfigFile.cjs +24 -0
- package/dist/_chunks-cjs/findConfigFile.cjs.map +1 -0
- package/dist/_chunks-cjs/index.cjs +231 -1910
- package/dist/_chunks-cjs/index.cjs.map +1 -1
- package/dist/_chunks-cjs/index2.cjs +781 -0
- package/dist/_chunks-cjs/index2.cjs.map +1 -0
- package/dist/_chunks-cjs/index3.cjs +50 -0
- package/dist/_chunks-cjs/index3.cjs.map +1 -0
- package/dist/_chunks-cjs/printPackageTree.cjs +42 -0
- package/dist/_chunks-cjs/printPackageTree.cjs.map +1 -0
- package/dist/_chunks-cjs/resolveBuildContext.cjs +176 -0
- package/dist/_chunks-cjs/resolveBuildContext.cjs.map +1 -0
- package/dist/_chunks-cjs/resolveBuildTasks.cjs +111 -0
- package/dist/_chunks-cjs/resolveBuildTasks.cjs.map +1 -0
- package/dist/_chunks-cjs/resolveConfigProperty.cjs +6 -0
- package/dist/_chunks-cjs/resolveConfigProperty.cjs.map +1 -0
- package/dist/_chunks-cjs/resolveWatchTasks.cjs +79 -0
- package/dist/_chunks-cjs/resolveWatchTasks.cjs.map +1 -0
- package/dist/_chunks-cjs/template.cjs +446 -0
- package/dist/_chunks-cjs/template.cjs.map +1 -0
- package/dist/_chunks-cjs/validatePkg.cjs +71 -0
- package/dist/_chunks-cjs/validatePkg.cjs.map +1 -0
- package/dist/_chunks-cjs/watchConfigFiles.cjs +59 -0
- package/dist/_chunks-cjs/watchConfigFiles.cjs.map +1 -0
- package/dist/_chunks-es/build.js +7 -107
- package/dist/_chunks-es/build.js.map +1 -1
- package/dist/_chunks-es/check.js +23 -44
- package/dist/_chunks-es/check.js.map +1 -1
- package/dist/_chunks-es/fileExists.js +12 -0
- package/dist/_chunks-es/fileExists.js.map +1 -0
- package/dist/_chunks-es/findConfigFile.js +23 -0
- package/dist/_chunks-es/findConfigFile.js.map +1 -0
- package/dist/_chunks-es/index.js +180 -754
- package/dist/_chunks-es/index.js.map +1 -1
- package/dist/_chunks-es/index2.js +769 -0
- package/dist/_chunks-es/index2.js.map +1 -0
- package/dist/_chunks-es/index3.js +51 -0
- package/dist/_chunks-es/index3.js.map +1 -0
- package/dist/_chunks-es/init.js +9 -493
- package/dist/_chunks-es/init.js.map +1 -1
- package/dist/_chunks-es/loadPkgWithReporting.js +100 -0
- package/dist/_chunks-es/loadPkgWithReporting.js.map +1 -0
- package/dist/_chunks-es/{isRecord.js → logger.js} +2 -15
- package/dist/_chunks-es/logger.js.map +1 -0
- package/dist/_chunks-es/printPackageTree.js +44 -0
- package/dist/_chunks-es/printPackageTree.js.map +1 -0
- package/dist/_chunks-es/resolveBuildContext.js +177 -0
- package/dist/_chunks-es/resolveBuildContext.js.map +1 -0
- package/dist/_chunks-es/resolveBuildTasks.js +109 -0
- package/dist/_chunks-es/resolveBuildTasks.js.map +1 -0
- package/dist/_chunks-es/resolveConfigProperty.js +7 -0
- package/dist/_chunks-es/resolveConfigProperty.js.map +1 -0
- package/dist/_chunks-es/resolveRolldownConfig.js +1 -1
- package/dist/_chunks-es/resolveWatchTasks.js +77 -0
- package/dist/_chunks-es/resolveWatchTasks.js.map +1 -0
- package/dist/_chunks-es/template.js +449 -0
- package/dist/_chunks-es/template.js.map +1 -0
- package/dist/_chunks-es/validatePkg.js +72 -0
- package/dist/_chunks-es/validatePkg.js.map +1 -0
- package/dist/_chunks-es/watch.js +9 -115
- package/dist/_chunks-es/watch.js.map +1 -1
- package/dist/_chunks-es/watchConfigFiles.js +45 -0
- package/dist/_chunks-es/watchConfigFiles.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/index.js +4 -7
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/_chunks-es/consoleSpy.js +0 -541
- package/dist/_chunks-es/consoleSpy.js.map +0 -1
- package/dist/_chunks-es/isRecord.js.map +0 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { ZodError } from "zod";
|
|
5
|
+
import fs from "node:fs/promises";
|
|
6
|
+
async function loadConfig(options) {
|
|
7
|
+
const [{ register }, { default: pkgUp }, { findConfigFile }] = await Promise.all([
|
|
8
|
+
import("esbuild-register/dist/node"),
|
|
9
|
+
import("pkg-up"),
|
|
10
|
+
import("./findConfigFile.js")
|
|
11
|
+
]), { cwd } = options, pkgPath = await pkgUp({ cwd });
|
|
12
|
+
if (!pkgPath) return;
|
|
13
|
+
const root = path.dirname(pkgPath), configFile = await findConfigFile(root);
|
|
14
|
+
if (!configFile || !configFile.startsWith(cwd))
|
|
15
|
+
return;
|
|
16
|
+
const esbuildOptions = { extensions: [".js", ".mjs", ".ts"] }, { unregister } = globalThis.__DEV__ ? { unregister: () => {
|
|
17
|
+
} } : register(esbuildOptions), mod = createRequire(import.meta.url)(configFile);
|
|
18
|
+
return unregister(), mod?.default || mod || void 0;
|
|
19
|
+
}
|
|
20
|
+
function assertLast(a, arr) {
|
|
21
|
+
const aIdx = arr.indexOf(a);
|
|
22
|
+
return aIdx === -1 ? !0 : aIdx === arr.length - 1;
|
|
23
|
+
}
|
|
24
|
+
function assertOrder(a, b, arr) {
|
|
25
|
+
const aIdx = arr.indexOf(a), bIdx = arr.indexOf(b);
|
|
26
|
+
return aIdx === -1 || bIdx === -1 ? !0 : aIdx < bIdx;
|
|
27
|
+
}
|
|
28
|
+
async function loadPkg(options) {
|
|
29
|
+
const [{ default: pkgUp }, { validatePkg }] = await Promise.all([
|
|
30
|
+
import("pkg-up"),
|
|
31
|
+
import("./validatePkg.js")
|
|
32
|
+
]), { cwd } = options, pkgPath = await pkgUp({ cwd });
|
|
33
|
+
if (!pkgPath) throw new Error("no package.json found");
|
|
34
|
+
const buf = await fs.readFile(pkgPath), raw = JSON.parse(buf.toString());
|
|
35
|
+
return validatePkg(raw), raw;
|
|
36
|
+
}
|
|
37
|
+
async function loadPkgWithReporting(options) {
|
|
38
|
+
const { cwd, logger, strict } = options;
|
|
39
|
+
try {
|
|
40
|
+
const pkg = await loadPkg({ cwd });
|
|
41
|
+
let shouldError = !1;
|
|
42
|
+
if (strict && (pkg.type || (shouldError = !0, logger.error(
|
|
43
|
+
'the `type` field in `./package.json` must be either "module" or "commonjs")'
|
|
44
|
+
))), pkg.exports) {
|
|
45
|
+
const _exports = Object.entries(pkg.exports);
|
|
46
|
+
for (const [expPath, exp] of _exports) {
|
|
47
|
+
if (typeof exp == "string" || "svelte" in exp)
|
|
48
|
+
continue;
|
|
49
|
+
const keys = Object.keys(exp);
|
|
50
|
+
exp.types && (shouldError = !0, logger.error(
|
|
51
|
+
`exports["${expPath}"]: the \`types\` condition shouldn't be used as dts files are generated in such a way that both CJS and ESM is supported`
|
|
52
|
+
)), exp.module && (shouldError = !0, logger.error(
|
|
53
|
+
`exports["${expPath}"]: the \`module\` condition shouldn't be used as it's not well supported in all bundlers.`
|
|
54
|
+
)), exp.node ? (exp.import && exp.node.import && !assertOrder("node", "import", keys) && (shouldError = !0, logger.error(
|
|
55
|
+
`exports["${expPath}"]: the \`node\` property should come before the \`import\` property`
|
|
56
|
+
)), exp.node.module && (shouldError = !0, logger.error(
|
|
57
|
+
`exports["${expPath}"]: the \`node.module\` condition shouldn't be used as it's not well supported in all bundlers. A better strategy is to refactor the codebase to no longer be vulnerable to the "dual package hazard"`
|
|
58
|
+
)), !exp.node.source && exp.node.import && (exp.node.require || exp.require) && (exp.node.import.endsWith(".cjs.js") || exp.node.import.endsWith(".cjs.mjs")) && (shouldError = !0, logger.error(
|
|
59
|
+
`exports["${expPath}"]: the \`node.import\` re-export pattern shouldn't be used as it's not well supported in all bundlers. A better strategy is to refactor the codebase to no longer be vulnerable to the "dual package hazard"`
|
|
60
|
+
)), exp.require && exp.node.require && exp.require === exp.node.require ? (shouldError = !0, logger.error(
|
|
61
|
+
`exports["${expPath}"]: the \`node.require\` property isn't necessary as it's identical to \`require\``
|
|
62
|
+
)) : exp.require && exp.node.require && !assertOrder("node", "require", keys) && (shouldError = !0, logger.error(
|
|
63
|
+
`exports["${expPath}"]: the \`node\` property should come before the \`require\` property`
|
|
64
|
+
))) : assertOrder("import", "require", keys) || logger.warn(
|
|
65
|
+
`exports["${expPath}"]: the \`import\` property should come before the \`require\` property`
|
|
66
|
+
), assertLast("default", keys) || (shouldError = !0, logger.error(
|
|
67
|
+
`exports["${expPath}"]: the \`default\` property should be the last property`
|
|
68
|
+
));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return shouldError && process.exit(1), pkg;
|
|
72
|
+
} catch (err) {
|
|
73
|
+
if (err instanceof ZodError)
|
|
74
|
+
for (const issue of err.issues) {
|
|
75
|
+
if (issue.code === "invalid_type") {
|
|
76
|
+
logger.error(
|
|
77
|
+
[
|
|
78
|
+
`\`${formatPath(issue.path)}\` `,
|
|
79
|
+
`in \`./package.json\` must be of type ${chalk.magenta(issue.expected)} `,
|
|
80
|
+
`(received ${chalk.magenta(issue.received)})`
|
|
81
|
+
].join("")
|
|
82
|
+
);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
logger.error(issue);
|
|
86
|
+
}
|
|
87
|
+
else
|
|
88
|
+
logger.error(err);
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function formatPath(segments) {
|
|
93
|
+
return segments.map((s, idx) => idx === 0 ? s : typeof s == "number" ? `[${s}]` : s.startsWith(".") ? `["${s}"]` : `.${s}`).join("");
|
|
94
|
+
}
|
|
95
|
+
export {
|
|
96
|
+
loadConfig,
|
|
97
|
+
loadPkg,
|
|
98
|
+
loadPkgWithReporting
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=loadPkgWithReporting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadPkgWithReporting.js","sources":["../../src/node/core/config/loadConfig.ts","../../src/node/core/pkg/helpers.ts","../../src/node/core/pkg/loadPkg.ts","../../src/node/core/pkg/loadPkgWithReporting.ts"],"sourcesContent":["import {createRequire} from 'node:module'\nimport path from 'node:path'\nimport type {PkgConfigOptions} from './types'\n\n/** @alpha */\nexport async function loadConfig(options: {cwd: string}): Promise<PkgConfigOptions | undefined> {\n const [{register}, {default: pkgUp}, {findConfigFile}] = await Promise.all([\n import('esbuild-register/dist/node'),\n import('pkg-up'),\n import('./findConfigFile'),\n ])\n const {cwd} = options\n\n const pkgPath = await pkgUp({cwd})\n\n if (!pkgPath) return undefined\n\n const root = path.dirname(pkgPath)\n\n const configFile = await findConfigFile(root)\n\n if (!configFile) {\n return undefined\n }\n\n // Do not accept config files outside of the root\n if (!configFile.startsWith(cwd)) {\n return undefined\n }\n\n const esbuildOptions = {extensions: ['.js', '.mjs', '.ts']}\n\n const {unregister} = globalThis.__DEV__ ? {unregister: () => undefined} : register(esbuildOptions)\n\n const require = createRequire(import.meta.url)\n const mod = require(configFile)\n\n unregister()\n\n return mod?.default || mod || undefined\n}\n","/** @internal */\nexport function assertFirst<T>(a: T, arr: T[]): boolean {\n const aIdx = arr.indexOf(a)\n\n // if not found, then we don't care\n if (aIdx === -1) {\n return true\n }\n\n return aIdx === 0\n}\n\n/** @internal */\nexport function assertLast<T>(a: T, arr: T[]): boolean {\n const aIdx = arr.indexOf(a)\n\n // if not found, then we don't care\n if (aIdx === -1) {\n return true\n }\n\n return aIdx === arr.length - 1\n}\n\n/** @internal */\nexport function assertOrder<T>(a: T, b: T, arr: T[]): boolean {\n const aIdx = arr.indexOf(a)\n const bIdx = arr.indexOf(b)\n\n // if either is not found, then we don't care\n if (aIdx === -1 || bIdx === -1) {\n return true\n }\n\n return aIdx < bIdx\n}\n","import fs from 'node:fs/promises'\nimport type {PackageJSON} from './types'\n\n/** @internal */\nexport async function loadPkg(options: {cwd: string}): Promise<PackageJSON> {\n const [{default: pkgUp}, {validatePkg}] = await Promise.all([\n import('pkg-up'),\n import('./validatePkg'),\n ])\n const {cwd} = options\n\n const pkgPath = await pkgUp({cwd})\n\n if (!pkgPath) throw new Error('no package.json found')\n\n const buf = await fs.readFile(pkgPath)\n\n const raw = JSON.parse(buf.toString())\n\n validatePkg(raw)\n\n return raw\n}\n","import chalk from 'chalk'\nimport {ZodError} from 'zod'\nimport type {Logger} from '../../logger'\nimport {assertLast, assertOrder} from './helpers'\nimport {loadPkg} from './loadPkg'\nimport type {PackageJSON} from './types'\n\n/** @alpha */\nexport async function loadPkgWithReporting(options: {\n cwd: string\n logger: Logger\n strict: boolean\n}): Promise<PackageJSON> {\n const {cwd, logger, strict} = options\n\n try {\n const pkg = await loadPkg({cwd})\n let shouldError = false\n\n if (strict) {\n if (!pkg.type) {\n shouldError = true\n logger.error(\n `the \\`type\\` field in \\`./package.json\\` must be either \"module\" or \"commonjs\")`,\n )\n }\n }\n\n // validate exports\n if (pkg.exports) {\n const _exports = Object.entries(pkg.exports)\n\n for (const [expPath, exp] of _exports) {\n if (typeof exp === 'string' || 'svelte' in exp) {\n continue\n }\n\n const keys = Object.keys(exp)\n\n if (exp.types) {\n shouldError = true\n logger.error(\n `exports[\"${expPath}\"]: the \\`types\\` condition shouldn't be used as dts files are generated in such a way that both CJS and ESM is supported`,\n )\n }\n\n if (exp.module) {\n shouldError = true\n logger.error(\n `exports[\"${expPath}\"]: the \\`module\\` condition shouldn't be used as it's not well supported in all bundlers.`,\n )\n }\n\n if (exp.node) {\n if (exp.import && exp.node.import && !assertOrder('node', 'import', keys)) {\n shouldError = true\n logger.error(\n `exports[\"${expPath}\"]: the \\`node\\` property should come before the \\`import\\` property`,\n )\n }\n\n if (exp.node.module) {\n shouldError = true\n logger.error(\n `exports[\"${expPath}\"]: the \\`node.module\\` condition shouldn't be used as it's not well supported in all bundlers. A better strategy is to refactor the codebase to no longer be vulnerable to the \"dual package hazard\"`,\n )\n }\n\n if (\n !exp.node.source &&\n exp.node.import &&\n (exp.node.require || exp.require) &&\n (exp.node.import.endsWith('.cjs.js') || exp.node.import.endsWith('.cjs.mjs'))\n ) {\n shouldError = true\n logger.error(\n `exports[\"${expPath}\"]: the \\`node.import\\` re-export pattern shouldn't be used as it's not well supported in all bundlers. A better strategy is to refactor the codebase to no longer be vulnerable to the \"dual package hazard\"`,\n )\n }\n\n if (exp.require && exp.node.require && exp.require === exp.node.require) {\n shouldError = true\n logger.error(\n `exports[\"${expPath}\"]: the \\`node.require\\` property isn't necessary as it's identical to \\`require\\``,\n )\n } else if (exp.require && exp.node.require && !assertOrder('node', 'require', keys)) {\n shouldError = true\n logger.error(\n `exports[\"${expPath}\"]: the \\`node\\` property should come before the \\`require\\` property`,\n )\n }\n } else {\n if (!assertOrder('import', 'require', keys)) {\n logger.warn(\n `exports[\"${expPath}\"]: the \\`import\\` property should come before the \\`require\\` property`,\n )\n }\n }\n\n if (!assertLast('default', keys)) {\n shouldError = true\n logger.error(\n `exports[\"${expPath}\"]: the \\`default\\` property should be the last property`,\n )\n }\n }\n }\n\n if (shouldError) {\n process.exit(1)\n }\n\n return pkg\n } catch (err) {\n if (err instanceof ZodError) {\n for (const issue of err.issues) {\n if (issue.code === 'invalid_type') {\n logger.error(\n [\n `\\`${formatPath(issue.path)}\\` `,\n `in \\`./package.json\\` must be of type ${chalk.magenta(issue.expected)} `,\n `(received ${chalk.magenta(issue.received)})`,\n ].join(''),\n )\n continue\n }\n\n logger.error(issue)\n }\n } else {\n logger.error(err)\n }\n\n process.exit(1)\n }\n}\n\nfunction formatPath(segments: Array<string | number>) {\n return segments\n .map((s, idx) => {\n if (idx === 0) return s\n\n if (typeof s === 'number') {\n return `[${s}]`\n }\n\n if (s.startsWith('.')) {\n return `[\"${s}\"]`\n }\n\n return `.${s}`\n })\n .join('')\n}\n"],"names":[],"mappings":";;;;;AAKA,eAAsB,WAAW,SAA+D;AAC9F,QAAM,CAAC,EAAC,YAAW,EAAC,SAAS,SAAQ,EAAC,eAAe,CAAA,IAAI,MAAM,QAAQ,IAAI;A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O;AAAA,UACL,YAAY,OAAO;AAAA,QAAA,GAKpB,WAAW,WAAW,IAAI,MAC7B,cAAc,IACd,OAAO;AAAA,UACL,YAAY,OAAO;AAAA,QAAA;AAAA,MACrB;AAAA,IAEJ;AAGF,WAAI,eACF,QAAQ,KAAK,CAAC,GAGT;AAAA,WACA,KAAK;AACZ,QAAI,eAAe;AACN,iBAAA,SAAS,IAAI,QAAQ;AAC1B,YAAA,MAAM,SAAS,gBAAgB;AAC1B,iBAAA;AAAA,YACL;AAAA,cACE,KAAK,WAAW,MAAM,IAAI,CAAC;AAAA,cAC3B,yCAAyC,MAAM,QAAQ,MAAM,QAAQ,CAAC;AAAA,cACtE,aAAa,MAAM,QAAQ,MAAM,QAAQ,CAAC;AAAA,YAC5C,EAAE,KAAK,EAAE;AAAA,UACX;AACA;AAAA,QAAA;AAGF,eAAO,MAAM,KAAK;AAAA,MAAA;AAAA;AAGpB,aAAO,MAAM,GAAG;AAGlB,YAAQ,KAAK,CAAC;AAAA,EAAA;AAElB;AAEA,SAAS,WAAW,UAAkC;AAC7C,SAAA,SACJ,IAAI,CAAC,GAAG,QACH,QAAQ,IAAU,IAElB,OAAO,KAAM,WACR,IAAI,CAAC,MAGV,EAAE,WAAW,GAAG,IACX,KAAK,CAAC,OAGR,IAAI,CAAC,EACb,EACA,KAAK,EAAE;AACZ;"}
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import { statSync } from "node:fs";
|
|
2
1
|
import chalk from "chalk";
|
|
3
|
-
function fileExists(filePath) {
|
|
4
|
-
try {
|
|
5
|
-
return statSync(filePath), !0;
|
|
6
|
-
} catch {
|
|
7
|
-
return !1;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
2
|
function createLogger() {
|
|
11
3
|
return {
|
|
12
4
|
log: (...args) => {
|
|
@@ -26,12 +18,7 @@ function createLogger() {
|
|
|
26
18
|
}
|
|
27
19
|
};
|
|
28
20
|
}
|
|
29
|
-
function isRecord(value) {
|
|
30
|
-
return !!value && !Array.isArray(value) && typeof value == "object";
|
|
31
|
-
}
|
|
32
21
|
export {
|
|
33
|
-
createLogger
|
|
34
|
-
fileExists,
|
|
35
|
-
isRecord
|
|
22
|
+
createLogger
|
|
36
23
|
};
|
|
37
|
-
//# sourceMappingURL=
|
|
24
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sources":["../../src/node/logger.ts"],"sourcesContent":["// oxlint-disable no-console\nimport chalk from 'chalk'\n\n/** @alpha */\nexport interface Logger {\n log: (...args: unknown[]) => void\n info: (...args: unknown[]) => void\n warn: (...args: unknown[]) => void\n error: (...args: unknown[]) => void\n success: (...args: unknown[]) => void\n}\n\n/** @alpha */\nexport function createLogger(): Logger {\n return {\n log: (...args) => {\n console.log(...args)\n },\n info: (...args) => {\n console.log(chalk.blue('[info]'), ...args)\n },\n warn: (...args) => {\n console.log(chalk.yellow('[warning]'), ...args)\n },\n error: (...args) => {\n console.log(chalk.red('[error]'), ...args)\n },\n success: (...args) => {\n console.log(chalk.green('[success]'), ...args)\n },\n }\n}\n"],"names":[],"mappings":";AAaO,SAAS,eAAuB;AAC9B,SAAA;AAAA,IACL,KAAK,IAAI,SAAS;AACR,cAAA,IAAI,GAAG,IAAI;AAAA,IACrB;AAAA,IACA,MAAM,IAAI,SAAS;AACjB,cAAQ,IAAI,MAAM,KAAK,QAAQ,GAAG,GAAG,IAAI;AAAA,IAC3C;AAAA,IACA,MAAM,IAAI,SAAS;AACjB,cAAQ,IAAI,MAAM,OAAO,WAAW,GAAG,GAAG,IAAI;AAAA,IAChD;AAAA,IACA,OAAO,IAAI,SAAS;AAClB,cAAQ,IAAI,MAAM,IAAI,SAAS,GAAG,GAAG,IAAI;AAAA,IAC3C;AAAA,IACA,SAAS,IAAI,SAAS;AACpB,cAAQ,IAAI,MAAM,MAAM,WAAW,GAAG,GAAG,IAAI;AAAA,IAAA;AAAA,EAEjD;AACF;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import treeify from "treeify";
|
|
4
|
+
import { fileExists } from "./fileExists.js";
|
|
5
|
+
import { statSync } from "node:fs";
|
|
6
|
+
import prettyBytes from "pretty-bytes";
|
|
7
|
+
function getFilesize(file) {
|
|
8
|
+
const stats = statSync(file);
|
|
9
|
+
return prettyBytes(stats.size);
|
|
10
|
+
}
|
|
11
|
+
function getFileInfo(cwd, filePath) {
|
|
12
|
+
const p = path.resolve(cwd, filePath), exists = fileExists(p), size = exists ? getFilesize(p) : void 0;
|
|
13
|
+
return { exists, size };
|
|
14
|
+
}
|
|
15
|
+
function printPackageTree(ctx) {
|
|
16
|
+
const { cwd, exports, logger, pkg } = ctx;
|
|
17
|
+
if (!exports) return;
|
|
18
|
+
logger.log(`${chalk.blue(pkg.name)}@${chalk.green(pkg.version)}`);
|
|
19
|
+
const tree = {};
|
|
20
|
+
pkg.type && (tree.type = chalk.yellow(pkg.type)), pkg.bin && (tree.bin = Object.fromEntries(
|
|
21
|
+
Object.entries(pkg.bin).map(([name, file]) => [chalk.cyan(name), fileInfo(file)])
|
|
22
|
+
));
|
|
23
|
+
function fileInfo(file) {
|
|
24
|
+
const info = getFileInfo(cwd, file);
|
|
25
|
+
return info.size ? `${chalk.yellow(file)} ${chalk.gray(info.size)}` : `${chalk.gray(file)} ${chalk.red("does not exist")}`;
|
|
26
|
+
}
|
|
27
|
+
tree.exports = Object.fromEntries(
|
|
28
|
+
Object.entries(exports).filter(([, entry]) => entry._exported).map(([exportPath, entry]) => {
|
|
29
|
+
const exp = {
|
|
30
|
+
source: fileInfo(entry.source),
|
|
31
|
+
browser: void 0,
|
|
32
|
+
require: void 0,
|
|
33
|
+
node: void 0,
|
|
34
|
+
import: void 0,
|
|
35
|
+
default: fileInfo(entry.default)
|
|
36
|
+
};
|
|
37
|
+
return entry.browser ? (exp.browser = { source: fileInfo(entry.browser.source) }, entry.browser.import && (exp.browser.import = fileInfo(entry.browser.import)), entry.browser.require && (exp.browser.require = fileInfo(entry.browser.require))) : delete exp.browser, entry.require ? exp.require = fileInfo(entry.require) : delete exp.require, entry.node ? (exp.node = {}, entry.node.source && (exp.node.source = fileInfo(entry.node.source)), entry.node.import && (exp.node.import = fileInfo(entry.node.import)), entry.node.require && (exp.node.require = fileInfo(entry.node.require))) : delete exp.node, entry.import ? exp.import = fileInfo(entry.import) : delete exp.import, [chalk.cyan(path.join(pkg.name, exportPath)), exp];
|
|
38
|
+
})
|
|
39
|
+
), logger.log(treeify.asTree(tree, !0, !0));
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
printPackageTree
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=printPackageTree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"printPackageTree.js","sources":["../../src/node/getFilesize.ts","../../src/node/printPackageTree.ts"],"sourcesContent":["import {statSync} from 'node:fs'\nimport prettyBytes from 'pretty-bytes'\n\nexport function getFilesize(file: string): string {\n const stats = statSync(file)\n\n return prettyBytes(stats.size)\n}\n","import path from 'node:path'\nimport chalk from 'chalk'\nimport treeify from 'treeify'\nimport type {PkgExport} from './core/config/types'\nimport type {BuildContext} from './core/contexts/buildContext'\nimport {fileExists} from './fileExists'\nimport {getFilesize} from './getFilesize'\n\nfunction getFileInfo(cwd: string, filePath: string) {\n const p = path.resolve(cwd, filePath)\n const exists = fileExists(p)\n const size = exists ? getFilesize(p) : undefined\n\n return {exists, size}\n}\n\nexport function printPackageTree(ctx: BuildContext): void {\n const {cwd, exports, logger, pkg} = ctx\n\n if (!exports) return\n\n logger.log(`${chalk.blue(pkg.name)}@${chalk.green(pkg.version)}`)\n\n const tree: Record<string, unknown> = {}\n\n if (pkg.type) {\n tree['type'] = chalk.yellow(pkg.type)\n }\n\n if (pkg.bin) {\n tree['bin'] = Object.fromEntries(\n Object.entries(pkg.bin).map(([name, file]) => [chalk.cyan(name), fileInfo(file)]),\n )\n }\n\n function fileInfo(file: string) {\n const info = getFileInfo(cwd, file)\n\n if (!info.size) {\n return `${chalk.gray(file)} ${chalk.red('does not exist')}`\n }\n\n return `${chalk.yellow(file)} ${chalk.gray(info.size)}`\n }\n\n tree['exports'] = Object.fromEntries(\n Object.entries(exports)\n .filter(([, entry]) => entry._exported)\n .map(([exportPath, entry]) => {\n const exp: Omit<PkgExport, '_exported'> = {\n source: fileInfo(entry.source),\n browser: undefined,\n require: undefined,\n node: undefined,\n import: undefined,\n default: fileInfo(entry.default),\n }\n\n if (entry.browser) {\n exp.browser = {source: fileInfo(entry.browser.source)}\n\n if (entry.browser.import) exp.browser.import = fileInfo(entry.browser.import)\n if (entry.browser.require) exp.browser.require = fileInfo(entry.browser.require)\n } else {\n delete exp.browser\n }\n\n if (entry.require) {\n exp.require = fileInfo(entry.require)\n } else {\n delete exp.require\n }\n\n if (entry.node) {\n exp.node = {}\n\n if (entry.node.source) exp.node.source = fileInfo(entry.node.source)\n if (entry.node.import) exp.node.import = fileInfo(entry.node.import)\n if (entry.node.require) exp.node.require = fileInfo(entry.node.require)\n } else {\n delete exp.node\n }\n\n if (entry.import) {\n exp.import = fileInfo(entry.import)\n } else {\n delete exp.import\n }\n\n return [chalk.cyan(path.join(pkg.name, exportPath)), exp]\n }),\n )\n\n logger.log(treeify.asTree(tree as Record<string, any>, true, true))\n}\n"],"names":[],"mappings":";;;;;;AAGO,SAAS,YAAY,MAAsB;AAC1C,QAAA,QAAQ,SAAS,IAAI;AAEpB,SAAA,YAAY,MAAM,IAAI;AAC/B;ACCA,SAAS,YAAY,KAAa,UAAkB;AAClD,QAAM,IAAI,KAAK,QAAQ,KAAK,QAAQ,GAC9B,SAAS,WAAW,CAAC,GACrB,OAAO,SAAS,YAAY,CAAC,IAAI;AAEhC,SAAA,EAAC,QAAQ,KAAI;AACtB;AAEO,SAAS,iBAAiB,KAAyB;AACxD,QAAM,EAAC,KAAK,SAAS,QAAQ,IAAO,IAAA;AAEpC,MAAI,CA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IAAI,SAGT,MAAM,QACR,IAAI,OAAO,CAEP,GAAA,MAAM,KAAK,WAAQ,IAAI,KAAK,SAAS,SAAS,MAAM,KAAK,MAAM,IAC/D,MAAM,KAAK,WAAQ,IAAI,KAAK,SAAS,SAAS,MAAM,KAAK,MAAM,IAC/D,MAAM,KAAK,YAAS,IAAI,KAAK,UAAU,SAAS,MAAM,KAAK,OAAO,MAEtE,OAAO,IAAI,MAGT,MAAM,SACR,IAAI,SAAS,SAAS,MAAM,MAAM,IAElC,OAAO,IAAI,QAGN,CAAC,MAAM,KAAK,KAAK,KAAK,IAAI,MAAM,UAAU,CAAC,GAAG,GAAG;AAAA,IACzD,CAAA;AAAA,EAAA,GAGL,OAAO,IAAI,QAAQ,OAAO,MAA6B,IAAM,EAAI,CAAC;AACpE;"}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import browserslist from "browserslist";
|
|
3
|
+
import { resolveConfigProperty } from "./resolveConfigProperty.js";
|
|
4
|
+
import { parseStrictOptions, DEFAULT_BROWSERSLIST_QUERY, parseExports } from "./index.js";
|
|
5
|
+
import ts from "typescript";
|
|
6
|
+
function browserslistToEsbuild(browserslistConfig, options = {}) {
|
|
7
|
+
if (!browserslistConfig) {
|
|
8
|
+
const path2 = process.cwd();
|
|
9
|
+
browserslistConfig = browserslist.loadConfig({ path: path2, ...options });
|
|
10
|
+
}
|
|
11
|
+
const SUPPORTED_ESBUILD_TARGETS = [
|
|
12
|
+
"es",
|
|
13
|
+
"chrome",
|
|
14
|
+
"edge",
|
|
15
|
+
"firefox",
|
|
16
|
+
"ios",
|
|
17
|
+
"node",
|
|
18
|
+
"safari",
|
|
19
|
+
"opera",
|
|
20
|
+
"ie"
|
|
21
|
+
], UNSUPPORTED = ["android 4"], replaces = {
|
|
22
|
+
ios_saf: "ios",
|
|
23
|
+
android: "chrome"
|
|
24
|
+
}, separator = " ";
|
|
25
|
+
return browserslist(browserslistConfig, options).filter((b) => !UNSUPPORTED.some((u) => b.startsWith(u))).map((b) => b === "safari TP" ? browserslist("last 1 safari version")[0] : b).map((b) => b.split(separator)).map((b) => (replaces[b[0]] && (b[0] = replaces[b[0]]), b)).map((b) => (b[1].includes("-") && (b[1] = b[1].slice(0, b[1].indexOf("-"))), b)).map((b) => (b[1].endsWith(".0") && (b[1] = b[1].slice(0, -2)), b)).filter((b) => /^\d+(\.\d+)*$/.test(b[1])).filter((b) => SUPPORTED_ESBUILD_TARGETS.includes(b[0])).reduce((acc, b) => {
|
|
26
|
+
const existingIndex = acc.findIndex((br) => br[0] === b[0]);
|
|
27
|
+
return existingIndex !== -1 ? acc[existingIndex][1] = b[1] : acc.push(b), acc;
|
|
28
|
+
}, []).map((b) => b.join(""));
|
|
29
|
+
}
|
|
30
|
+
function pathContains(containerPath, itemPath) {
|
|
31
|
+
return !path.relative(containerPath, itemPath).startsWith("..");
|
|
32
|
+
}
|
|
33
|
+
function findCommonDirPath(filePaths) {
|
|
34
|
+
let ret;
|
|
35
|
+
for (const filePath of filePaths) {
|
|
36
|
+
let dirPath = path.dirname(filePath);
|
|
37
|
+
if (!ret) {
|
|
38
|
+
ret = dirPath;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
for (; dirPath !== ret && (dirPath = path.dirname(dirPath), dirPath !== ret); ) {
|
|
42
|
+
if (pathContains(dirPath, ret)) {
|
|
43
|
+
ret = dirPath;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
if (dirPath === ".") return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return ret;
|
|
50
|
+
}
|
|
51
|
+
async function loadTSConfig(options) {
|
|
52
|
+
const { cwd, tsconfigPath } = options, configPath = ts.findConfigFile(cwd, ts.sys.fileExists, tsconfigPath);
|
|
53
|
+
if (!configPath)
|
|
54
|
+
return;
|
|
55
|
+
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
56
|
+
return ts.parseJsonConfigFileContent(configFile.config, ts.sys, cwd);
|
|
57
|
+
}
|
|
58
|
+
function resolveBrowserTarget(versions) {
|
|
59
|
+
const target = versions.filter(
|
|
60
|
+
(version) => version.startsWith("chrome") || version.startsWith("edge") || version.startsWith("firefox") || version.startsWith("ios") || version.startsWith("safari") || version.startsWith("opera")
|
|
61
|
+
);
|
|
62
|
+
if (target.length !== 0)
|
|
63
|
+
return target;
|
|
64
|
+
}
|
|
65
|
+
function resolveNodeTarget(versions) {
|
|
66
|
+
const target = versions.filter((version) => version.startsWith("node"));
|
|
67
|
+
if (target.length !== 0)
|
|
68
|
+
return target;
|
|
69
|
+
}
|
|
70
|
+
async function resolveBuildContext(options) {
|
|
71
|
+
const {
|
|
72
|
+
config,
|
|
73
|
+
cwd,
|
|
74
|
+
emitDeclarationOnly = !1,
|
|
75
|
+
logger,
|
|
76
|
+
pkg,
|
|
77
|
+
strict,
|
|
78
|
+
tsconfig: tsconfigPath
|
|
79
|
+
} = options, tsconfig = await loadTSConfig({ cwd, tsconfigPath }), strictOptions = parseStrictOptions(config?.strictOptions ?? {});
|
|
80
|
+
let browserslist2 = pkg.browserslist;
|
|
81
|
+
if (!browserslist2) {
|
|
82
|
+
if (strict && strictOptions.noImplicitBrowsersList !== "off") {
|
|
83
|
+
if (strictOptions.noImplicitBrowsersList === "error")
|
|
84
|
+
throw new Error(
|
|
85
|
+
'\n- package.json: "browserslist" is missing, set it to `"browserslist": "extends @sanity/browserslist-config"`'
|
|
86
|
+
);
|
|
87
|
+
logger.warn(
|
|
88
|
+
'Could not detect a `browserslist` property in `package.json`, using default configuration. Add `"browserslist": "extends @sanity/browserslist-config"` to silence this warning.'
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
browserslist2 = DEFAULT_BROWSERSLIST_QUERY;
|
|
92
|
+
}
|
|
93
|
+
const targetVersions = browserslistToEsbuild(browserslist2);
|
|
94
|
+
if (strict && strictOptions.noImplicitSideEffects !== "off" && typeof pkg.sideEffects > "u") {
|
|
95
|
+
const msg = "package.json: `sideEffects` is missing, see https://webpack.js.org/guides/tree-shaking/#clarifying-tree-shaking-and-sideeffects for how to define `sideEffects`";
|
|
96
|
+
if (strictOptions.noImplicitSideEffects === "error")
|
|
97
|
+
throw new Error(msg);
|
|
98
|
+
logger.warn(msg);
|
|
99
|
+
}
|
|
100
|
+
const nodeTarget = resolveNodeTarget(targetVersions), webTarget = resolveBrowserTarget(targetVersions);
|
|
101
|
+
if (!nodeTarget)
|
|
102
|
+
throw new Error("no matching `node` target");
|
|
103
|
+
if (!webTarget)
|
|
104
|
+
throw new Error("no matching `web` target");
|
|
105
|
+
const target = {
|
|
106
|
+
"*": webTarget.concat(nodeTarget),
|
|
107
|
+
browser: webTarget,
|
|
108
|
+
node: nodeTarget
|
|
109
|
+
}, parsedExports = parseExports({
|
|
110
|
+
cwd,
|
|
111
|
+
pkg,
|
|
112
|
+
strict,
|
|
113
|
+
strictOptions,
|
|
114
|
+
logger
|
|
115
|
+
}).reduce(
|
|
116
|
+
(acc, { _path: exportPath, ...exportEntry }) => Object.assign(acc, { [exportPath]: exportEntry }),
|
|
117
|
+
{}
|
|
118
|
+
), exports = resolveConfigProperty(config?.exports, parsedExports), parsedExternal = [
|
|
119
|
+
...pkg.dependencies ? Object.keys(pkg.dependencies) : [],
|
|
120
|
+
...pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : []
|
|
121
|
+
], external = config && Array.isArray(config.external) ? [...parsedExternal, ...config.external] : resolveConfigProperty(config?.external, parsedExternal), externalWithTypes = /* @__PURE__ */ new Set([pkg.name, ...external, ...external.map(transformPackageName)]), bundledDependencies = (pkg.devDependencies ? Object.keys(pkg.devDependencies) : []).filter(
|
|
122
|
+
// Do not bundle anything that is marked as external
|
|
123
|
+
(_) => !externalWithTypes.has(_)
|
|
124
|
+
), bundledPackages = config && Array.isArray(config.extract?.bundledPackages) ? [...bundledDependencies, ...config.extract.bundledPackages] : resolveConfigProperty(config?.extract?.bundledPackages, bundledDependencies), outputPaths = Object.values(exports).flatMap((exportEntry) => [
|
|
125
|
+
exportEntry.import,
|
|
126
|
+
exportEntry.require,
|
|
127
|
+
exportEntry.browser?.import,
|
|
128
|
+
exportEntry.browser?.require,
|
|
129
|
+
exportEntry.node?.source && exportEntry.node.import,
|
|
130
|
+
exportEntry.node?.source && exportEntry.node.require
|
|
131
|
+
].filter(Boolean)).map((p) => path.resolve(cwd, p)), commonDistPath = findCommonDirPath(outputPaths);
|
|
132
|
+
if (commonDistPath === cwd)
|
|
133
|
+
throw new Error(
|
|
134
|
+
"all output files must share a common parent directory which is not the root package directory"
|
|
135
|
+
);
|
|
136
|
+
if (commonDistPath && !pathContains(cwd, commonDistPath))
|
|
137
|
+
throw new Error("all output files must be located within the package");
|
|
138
|
+
const configDistPath = config?.dist ? path.resolve(cwd, config.dist) : void 0;
|
|
139
|
+
if (configDistPath && commonDistPath && configDistPath !== commonDistPath && !pathContains(configDistPath, commonDistPath))
|
|
140
|
+
throw logger.log(`did you mean to configure \`dist: './${path.relative(cwd, commonDistPath)}'\`?`), new Error("all output files must be located with the configured `dist` path");
|
|
141
|
+
const distPath = configDistPath || commonDistPath;
|
|
142
|
+
if (!distPath)
|
|
143
|
+
throw new Error("could not detect `dist` path");
|
|
144
|
+
return {
|
|
145
|
+
config,
|
|
146
|
+
cwd,
|
|
147
|
+
distPath,
|
|
148
|
+
emitDeclarationOnly,
|
|
149
|
+
exports,
|
|
150
|
+
external,
|
|
151
|
+
bundledPackages,
|
|
152
|
+
files: [],
|
|
153
|
+
logger,
|
|
154
|
+
pkg,
|
|
155
|
+
runtime: config?.runtime ?? "*",
|
|
156
|
+
strict,
|
|
157
|
+
target,
|
|
158
|
+
ts: {
|
|
159
|
+
config: tsconfig,
|
|
160
|
+
configPath: tsconfigPath
|
|
161
|
+
},
|
|
162
|
+
dts: config?.dts === "rolldown" ? "rolldown" : "api-extractor"
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function transformPackageName(packageName) {
|
|
166
|
+
if (packageName.startsWith("@types/"))
|
|
167
|
+
return packageName;
|
|
168
|
+
if (packageName.startsWith("@")) {
|
|
169
|
+
const [scope, name] = packageName.split("/");
|
|
170
|
+
return `@types/${scope.slice(1)}__${name}`;
|
|
171
|
+
} else
|
|
172
|
+
return `@types/${packageName}`;
|
|
173
|
+
}
|
|
174
|
+
export {
|
|
175
|
+
resolveBuildContext
|
|
176
|
+
};
|
|
177
|
+
//# sourceMappingURL=resolveBuildContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveBuildContext.js","sources":["../../node_modules/.pnpm/browserslist-to-esbuild@2.1.1_browserslist@4.25.0/node_modules/browserslist-to-esbuild/src/index.js","../../src/node/core/findCommonPath.ts","../../src/node/core/ts/loadTSConfig.ts","../../src/node/resolveBrowserTarget.ts","../../src/node/resolveNodeTarget.ts","../../src/node/resolveBuildContext.ts"],"sourcesContent":["import browserslist from 'browserslist'\n\n// convert the browserslist field in package.json to\n// esbuild compatible array of browsers\nexport default function browserslistToEsbuild(browserslistConfig, options = {}) {\n if (!browserslistConfig) {\n // the path from where the script is run\n const path = process.cwd()\n\n // read config if none is passed\n browserslistConfig = browserslist.loadConfig({ path, ...options })\n }\n\n const SUPPORTED_ESBUILD_TARGETS = [\n 'es',\n 'chrome',\n 'edge',\n 'firefox',\n 'ios',\n 'node',\n 'safari',\n 'opera',\n 'ie',\n ]\n\n // https://github.com/eBay/browserslist-config/issues/16#issuecomment-863870093\n const UNSUPPORTED = ['android 4']\n\n const replaces = {\n ios_saf: 'ios',\n android: 'chrome',\n }\n\n const separator = ' '\n\n return (\n browserslist(browserslistConfig, options)\n // filter out the unsupported ones\n .filter((b) => !UNSUPPORTED.some((u) => b.startsWith(u)))\n // replaces safari TP with latest safari version\n .map((b) => {\n if (b === 'safari TP') {\n return browserslist('last 1 safari version')[0]\n }\n\n return b\n })\n // transform into ['chrome', '88']\n .map((b) => b.split(separator))\n // replace the similar browser\n .map((b) => {\n if (replaces[b[0]]) {\n b[0] = replaces[b[0]]\n }\n\n return b\n })\n // 11.0-12.0 --> 11.0\n .map((b) => {\n if (b[1].includes('-')) {\n b[1] = b[1].slice(0, b[1].indexOf('-'))\n }\n\n return b\n })\n // 11.0 --> 11\n .map((b) => {\n if (b[1].endsWith('.0')) {\n b[1] = b[1].slice(0, -2)\n }\n\n return b\n })\n // removes invalid versions that will break esbuild\n // https://github.com/evanw/esbuild/blob/35c0d65b9d4f29a26176404d2890d1b499634e9f/compat-table/src/caniuse.ts#L119-L122\n .filter((b) => /^\\d+(\\.\\d+)*$/.test(b[1]))\n // only get the targets supported by esbuild\n .filter((b) => SUPPORTED_ESBUILD_TARGETS.includes(b[0]))\n // only get the oldest version, assuming that the older version\n // is last in the array\n .reduce((acc, b) => {\n const existingIndex = acc.findIndex((br) => br[0] === b[0])\n\n if (existingIndex !== -1) {\n acc[existingIndex][1] = b[1]\n } else {\n acc.push(b)\n }\n return acc\n }, [])\n // remove separator\n .map((b) => b.join(''))\n )\n}\n","import path from 'node:path'\n\nexport function pathContains(containerPath: string, itemPath: string): boolean {\n return !path.relative(containerPath, itemPath).startsWith('..')\n}\n\nexport function findCommonDirPath(filePaths: string[]): string | undefined {\n let ret: string | undefined = undefined\n\n for (const filePath of filePaths) {\n let dirPath = path.dirname(filePath)\n\n if (!ret) {\n ret = dirPath\n continue\n }\n\n while (dirPath !== ret) {\n dirPath = path.dirname(dirPath)\n\n if (dirPath === ret) {\n break\n }\n\n if (pathContains(dirPath, ret)) {\n ret = dirPath\n break\n }\n\n if (dirPath === '.') return undefined\n }\n }\n\n return ret\n}\n","import ts from 'typescript'\n\n/** @internal */\nexport async function loadTSConfig(options: {\n cwd: string\n tsconfigPath: string\n}): Promise<ts.ParsedCommandLine | undefined> {\n const {cwd, tsconfigPath} = options\n\n const configPath = ts.findConfigFile(cwd, ts.sys.fileExists, tsconfigPath)\n\n if (!configPath) {\n return undefined\n }\n\n const configFile = ts.readConfigFile(configPath, ts.sys.readFile)\n\n return ts.parseJsonConfigFileContent(configFile.config, ts.sys, cwd)\n}\n","export function resolveBrowserTarget(versions: string[]): string[] | undefined {\n const target: string[] = versions.filter(\n (version) =>\n version.startsWith('chrome') ||\n version.startsWith('edge') ||\n version.startsWith('firefox') ||\n version.startsWith('ios') ||\n version.startsWith('safari') ||\n version.startsWith('opera'),\n )\n\n if (target.length === 0) {\n return undefined\n }\n\n return target\n}\n","export function resolveNodeTarget(versions: string[]): string[] | undefined {\n const target: string[] = versions.filter((version) => version.startsWith('node'))\n\n if (target.length === 0) {\n return undefined\n }\n\n return target\n}\n","import path from 'node:path'\nimport browserslistToEsbuild from 'browserslist-to-esbuild'\nimport {resolveConfigProperty} from './core/config/resolveConfigProperty'\nimport {type PkgConfigOptions, type PkgExports, type PkgRuntime} from './core/config/types'\nimport type {BuildContext} from './core/contexts/buildContext'\nimport {DEFAULT_BROWSERSLIST_QUERY} from './core/defaults'\nimport {findCommonDirPath, pathContains} from './core/findCommonPath'\nimport {parseExports} from './core/pkg/parseExports'\nimport type {PackageJSON} from './core/pkg/types'\nimport {loadTSConfig} from './core/ts/loadTSConfig'\nimport type {Logger} from './logger'\nimport {resolveBrowserTarget} from './resolveBrowserTarget'\nimport {resolveNodeTarget} from './resolveNodeTarget'\nimport {parseStrictOptions} from './strict'\n\nexport async function resolveBuildContext(options: {\n config?: PkgConfigOptions\n cwd: string\n emitDeclarationOnly?: boolean\n logger: Logger\n pkg: PackageJSON\n strict: boolean\n tsconfig: string\n}): Promise<BuildContext> {\n const {\n config,\n cwd,\n emitDeclarationOnly = false,\n logger,\n pkg,\n strict,\n tsconfig: tsconfigPath,\n } = options\n const tsconfig = await loadTSConfig({cwd, tsconfigPath})\n const strictOptions = parseStrictOptions(config?.strictOptions ?? {})\n\n let browserslist = pkg.browserslist\n if (!browserslist) {\n if (strict && strictOptions.noImplicitBrowsersList !== 'off') {\n if (strictOptions.noImplicitBrowsersList === 'error') {\n throw new Error(\n '\\n- ' +\n `package.json: \"browserslist\" is missing, set it to \\`\"browserslist\": \"extends @sanity/browserslist-config\"\\``,\n )\n } else {\n logger.warn(\n 'Could not detect a `browserslist` property in `package.json`, using default configuration. Add `\"browserslist\": \"extends @sanity/browserslist-config\"` to silence this warning.',\n )\n }\n }\n browserslist = DEFAULT_BROWSERSLIST_QUERY\n }\n const targetVersions = browserslistToEsbuild(browserslist)\n\n if (\n strict &&\n strictOptions.noImplicitSideEffects !== 'off' &&\n typeof pkg.sideEffects === 'undefined'\n ) {\n const msg =\n 'package.json: `sideEffects` is missing, see https://webpack.js.org/guides/tree-shaking/#clarifying-tree-shaking-and-sideeffects for how to define `sideEffects`'\n\n if (strictOptions.noImplicitSideEffects === 'error') {\n throw new Error(msg)\n } else {\n logger.warn(msg)\n }\n }\n\n const nodeTarget = resolveNodeTarget(targetVersions)\n const webTarget = resolveBrowserTarget(targetVersions)\n\n if (!nodeTarget) {\n throw new Error('no matching `node` target')\n }\n\n if (!webTarget) {\n throw new Error('no matching `web` target')\n }\n\n const target: Record<PkgRuntime, string[]> = {\n '*': webTarget.concat(nodeTarget),\n 'browser': webTarget,\n 'node': nodeTarget,\n }\n\n const parsedExports = parseExports({\n cwd,\n pkg,\n strict,\n strictOptions,\n logger,\n }).reduce<PkgExports>(\n (acc, {_path: exportPath, ...exportEntry}) => Object.assign(acc, {[exportPath]: exportEntry}),\n {},\n )\n\n const exports = resolveConfigProperty(config?.exports, parsedExports)\n\n const parsedExternal = [\n ...(pkg.dependencies ? Object.keys(pkg.dependencies) : []),\n ...(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : []),\n ]\n\n // Merge externals if an array is provided, replace if it's a function\n const external =\n config && Array.isArray(config.external)\n ? [...parsedExternal, ...config.external]\n : resolveConfigProperty(config?.external, parsedExternal)\n // Merge bundledPackages with dev deps, replace if it's a function\n const externalWithTypes = new Set([pkg.name, ...external, ...external.map(transformPackageName)])\n const bundledDependencies = (pkg.devDependencies ? Object.keys(pkg.devDependencies) : []).filter(\n // Do not bundle anything that is marked as external\n (_) => !externalWithTypes.has(_),\n )\n const bundledPackages =\n config && Array.isArray(config.extract?.bundledPackages)\n ? [...bundledDependencies, ...config.extract.bundledPackages]\n : resolveConfigProperty(config?.extract?.bundledPackages, bundledDependencies)\n\n const outputPaths = Object.values(exports)\n .flatMap((exportEntry) => {\n return [\n exportEntry.import,\n exportEntry.require,\n exportEntry.browser?.import,\n exportEntry.browser?.require,\n exportEntry.node?.source && exportEntry.node.import,\n exportEntry.node?.source && exportEntry.node.require,\n ].filter(Boolean) as string[]\n })\n .map((p) => path.resolve(cwd, p))\n\n const commonDistPath = findCommonDirPath(outputPaths)\n\n if (commonDistPath === cwd) {\n throw new Error(\n 'all output files must share a common parent directory which is not the root package directory',\n )\n }\n\n if (commonDistPath && !pathContains(cwd, commonDistPath)) {\n throw new Error('all output files must be located within the package')\n }\n\n const configDistPath = config?.dist ? path.resolve(cwd, config.dist) : undefined\n\n if (\n configDistPath &&\n commonDistPath &&\n configDistPath !== commonDistPath &&\n !pathContains(configDistPath, commonDistPath)\n ) {\n logger.log(`did you mean to configure \\`dist: './${path.relative(cwd, commonDistPath)}'\\`?`)\n\n throw new Error('all output files must be located with the configured `dist` path')\n }\n\n const distPath = configDistPath || commonDistPath\n\n if (!distPath) {\n throw new Error('could not detect `dist` path')\n }\n\n const ctx: BuildContext = {\n config,\n cwd,\n distPath,\n emitDeclarationOnly,\n exports,\n external,\n bundledPackages,\n files: [],\n logger,\n pkg,\n runtime: config?.runtime ?? '*',\n strict,\n target,\n ts: {\n config: tsconfig,\n configPath: tsconfigPath,\n },\n dts: config?.dts === 'rolldown' ? 'rolldown' : 'api-extractor',\n }\n\n return ctx\n}\n\nfunction transformPackageName(packageName: string): string {\n if (packageName.startsWith('@types/')) {\n // If it already starts with @types, return it as is\n return packageName\n } else if (packageName.startsWith('@')) {\n // Handle scoped packages\n const [scope, name] = packageName.split('/')\n\n return `@types/${scope.slice(1)}__${name}`\n } else {\n // Handle regular packages\n return `@types/${packageName}`\n }\n}\n"],"names":["path","browserslist"],"mappings":";;;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kB,CAAC,aAAa,KAAK,cAAc;AAC/C,UAAA,IAAI,MAAM,qDAAqD;AAGjE,QAAA,iBAAiB,QAAQ,OAAO,KAAK,QAAQ,KAAK,OAAO,IAAI,IAAI;AAEvE,MACE,kBACA,kBACA,mBAAmB,kBACnB,CAAC,aAAa,gBAAgB,cAAc;AAErC,UAAA,OAAA,IAAI,wCAAwC,KAAK,SAAS,KAAK,cAAc,CAAC,MAAM,GAErF,IAAI,MAAM,kEAAkE;AAGpF,QAAM,WAAW,kBAAkB;AAEnC,MAAI,CAAC;AACG,UAAA,IAAI,MAAM,8BAA8B;AAGtB,SAAA;AAAA,IACxB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,CAAC;AAAA,IACR;AAAA,IACA;AAAA,IACA,SAAS,QAAQ,WAAW;AAAA,IAC5B;AAAA,IACA;AAAA,IACA,IAAI;AAAA,MACF,QAAQ;AAAA,MACR,YAAY;AAAA,IACd;AAAA,IACA,KAAK,QAAQ,QAAQ,aAAa,aAAa;AAAA,EACjD;AAGF;AAEA,SAAS,qBAAqB,aAA6B;AACrD,MAAA,YAAY,WAAW,SAAS;AAE3B,WAAA;AACE,MAAA,YAAY,WAAW,GAAG,GAAG;AAEtC,UAAM,CAAC,OAAO,IAAI,IAAI,YAAY,MAAM,GAAG;AAE3C,WAAO,UAAU,MAAM,MAAM,CAAC,CAAC,KAAK,IAAI;AAAA,EAC1C;AAEE,WAAO,UAAU,WAAW;AAEhC;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { getTargetPaths } from "./index.js";
|
|
3
|
+
function resolveBuildTasks(ctx) {
|
|
4
|
+
const { config, pkg, target } = ctx, bundles = config?.bundles || [], tasks = [], exports = Object.entries(ctx.exports || {}).map(
|
|
5
|
+
([_path, exp]) => ({ _path, ...exp })
|
|
6
|
+
), dtsTask = {
|
|
7
|
+
type: "build:dts",
|
|
8
|
+
entries: []
|
|
9
|
+
}, rolldownDtsTask = {}, rollupTasks = {};
|
|
10
|
+
function addRollupTaskEntry(format, runtime, entry) {
|
|
11
|
+
const buildId = `${format}:${runtime}`;
|
|
12
|
+
ctx.dts === "rolldown" && (rolldownDtsTask[buildId] ? rolldownDtsTask[buildId].entries.push(entry) : rolldownDtsTask[buildId] = {
|
|
13
|
+
type: "rolldown:dts",
|
|
14
|
+
buildId,
|
|
15
|
+
entries: [entry],
|
|
16
|
+
runtime,
|
|
17
|
+
format,
|
|
18
|
+
target: target[runtime]
|
|
19
|
+
}), ctx.emitDeclarationOnly || (rollupTasks[buildId] ? rollupTasks[buildId].entries.push(entry) : rollupTasks[buildId] = {
|
|
20
|
+
type: "build:js",
|
|
21
|
+
buildId,
|
|
22
|
+
entries: [entry],
|
|
23
|
+
runtime,
|
|
24
|
+
format,
|
|
25
|
+
target: target[runtime]
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (ctx.dts === "api-extractor") {
|
|
29
|
+
for (const exp of exports) {
|
|
30
|
+
const importId = path.join(pkg.name, exp._path);
|
|
31
|
+
exp.source?.endsWith(".ts") && dtsTask.entries.push({
|
|
32
|
+
importId,
|
|
33
|
+
exportPath: exp._path,
|
|
34
|
+
sourcePath: exp.source,
|
|
35
|
+
targetPaths: getTargetPaths(pkg.type, exp)
|
|
36
|
+
}), exp.browser?.source?.endsWith(".ts") && dtsTask.entries.push({
|
|
37
|
+
importId,
|
|
38
|
+
exportPath: exp._path,
|
|
39
|
+
sourcePath: exp.browser.source,
|
|
40
|
+
targetPaths: getTargetPaths(pkg.type, exp.browser)
|
|
41
|
+
}), exp.node?.source?.endsWith(".ts") && dtsTask.entries.push({
|
|
42
|
+
importId,
|
|
43
|
+
exportPath: exp._path,
|
|
44
|
+
sourcePath: exp.node.source,
|
|
45
|
+
targetPaths: getTargetPaths(pkg.type, exp.node)
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
for (const bundle of bundles)
|
|
49
|
+
if (bundle.source?.endsWith(".ts")) {
|
|
50
|
+
const exportPath = (bundle.import || bundle.require).replace(/\.[mc]?js$/, ""), importId = path.join(pkg.name, exportPath);
|
|
51
|
+
dtsTask.entries.push({
|
|
52
|
+
importId,
|
|
53
|
+
exportPath,
|
|
54
|
+
sourcePath: bundle.source,
|
|
55
|
+
targetPaths: getTargetPaths(pkg.type, bundle)
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
dtsTask.entries.length && tasks.push(dtsTask);
|
|
59
|
+
}
|
|
60
|
+
for (const exp of exports) {
|
|
61
|
+
const output = exp.require;
|
|
62
|
+
output && addRollupTaskEntry("commonjs", ctx.runtime, {
|
|
63
|
+
path: exp._path,
|
|
64
|
+
source: exp.source,
|
|
65
|
+
output
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
for (const exp of exports) {
|
|
69
|
+
const output = exp.import;
|
|
70
|
+
output && addRollupTaskEntry("esm", ctx.runtime, {
|
|
71
|
+
path: exp._path,
|
|
72
|
+
source: exp.source,
|
|
73
|
+
output
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
for (const exp of exports) {
|
|
77
|
+
const output = exp.browser?.require;
|
|
78
|
+
output && addRollupTaskEntry("commonjs", "browser", {
|
|
79
|
+
path: exp._path,
|
|
80
|
+
source: exp.browser?.source || exp.source,
|
|
81
|
+
output
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
for (const exp of exports) {
|
|
85
|
+
const output = exp.browser?.import;
|
|
86
|
+
output && addRollupTaskEntry("esm", "browser", {
|
|
87
|
+
path: exp._path,
|
|
88
|
+
source: exp.browser?.source || exp.source,
|
|
89
|
+
output
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
for (const bundle of bundles) {
|
|
93
|
+
const idx = bundles.indexOf(bundle);
|
|
94
|
+
bundle.require && addRollupTaskEntry("commonjs", bundle.runtime || ctx.runtime, {
|
|
95
|
+
path: `__$$bundle_cjs_${idx}$$__`,
|
|
96
|
+
source: bundle.source,
|
|
97
|
+
output: bundle.require
|
|
98
|
+
}), bundle.import && addRollupTaskEntry("esm", bundle.runtime || ctx.runtime, {
|
|
99
|
+
path: `__$$bundle_esm_${idx}$$__`,
|
|
100
|
+
source: bundle.source,
|
|
101
|
+
output: bundle.import
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return tasks.push(...Object.values(rolldownDtsTask)), tasks.push(...Object.values(rollupTasks)), tasks;
|
|
105
|
+
}
|
|
106
|
+
export {
|
|
107
|
+
resolveBuildTasks
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=resolveBuildTasks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveBuildTasks.js","sources":["../../src/node/resolveBuildTasks.ts"],"sourcesContent":["import path from 'node:path'\nimport type {PkgExport, PkgFormat, PkgRuntime} from './core/config/types'\nimport type {BuildContext} from './core/contexts/buildContext'\nimport {getTargetPaths} from './tasks/dts/getTargetPaths'\nimport type {DtsTask} from './tasks/dts/types'\nimport type {BuildTask, RolldownDtsTask, RollupTask, RollupTaskEntry} from './tasks/types'\n\n/** @internal */\nexport function resolveBuildTasks(ctx: BuildContext): BuildTask[] {\n const {config, pkg, target} = ctx\n\n const bundles = config?.bundles || []\n\n const tasks: BuildTask[] = []\n\n const exports = Object.entries(ctx.exports || {}).map(\n ([_path, exp]) => ({_path, ...exp}) as PkgExport & {_path: string},\n )\n\n const dtsTask: DtsTask = {\n type: 'build:dts',\n entries: [],\n }\n\n const rolldownDtsTask: Record<string, RolldownDtsTask> = {}\n const rollupTasks: Record<string, RollupTask> = {}\n\n function addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: RollupTaskEntry) {\n const buildId = `${format}:${runtime}`\n\n if (ctx.dts === 'rolldown') {\n if (rolldownDtsTask[buildId]) {\n rolldownDtsTask[buildId].entries.push(entry)\n } else {\n rolldownDtsTask[buildId] = {\n type: 'rolldown:dts',\n buildId,\n entries: [entry],\n runtime,\n format,\n target: target[runtime],\n }\n }\n }\n\n if (!ctx.emitDeclarationOnly) {\n if (rollupTasks[buildId]) {\n rollupTasks[buildId].entries.push(entry)\n } else {\n rollupTasks[buildId] = {\n type: 'build:js',\n buildId,\n entries: [entry],\n runtime,\n format,\n target: target[runtime],\n }\n }\n }\n }\n\n if (ctx.dts === 'api-extractor') {\n // Parse `dts` tasks\n for (const exp of exports) {\n const importId = path.join(pkg.name, exp._path)\n\n if (exp.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.source,\n targetPaths: getTargetPaths(pkg.type, exp),\n })\n }\n\n if (exp.browser?.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.browser.source,\n targetPaths: getTargetPaths(pkg.type, exp.browser),\n })\n }\n\n if (exp.node?.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.node.source,\n targetPaths: getTargetPaths(pkg.type, exp.node),\n })\n }\n }\n\n // Handle dts tasks for bundles\n for (const bundle of bundles) {\n if (bundle.source?.endsWith('.ts')) {\n // importId needs to be how the bundle is used, like `@sanity/pkg-utils/dist/cli`\n // exportPath needs to be the path to the bundle, like `./dist/cli`\n // targetPaths is then: [./dist/cli.d.ts, ./dist/cli.d.cts]\n const exportPath = (bundle.import || bundle.require)!.replace(/\\.[mc]?js$/, '')\n const importId = path.join(pkg.name, exportPath)\n\n dtsTask.entries.push({\n importId,\n exportPath,\n sourcePath: bundle.source,\n targetPaths: getTargetPaths(pkg.type, bundle),\n })\n }\n }\n\n // Add dts task\n if (dtsTask.entries.length) {\n tasks.push(dtsTask)\n }\n }\n\n // Parse rollup:commonjs:* tasks\n for (const exp of exports) {\n const output = exp.require\n\n if (!output) continue\n\n addRollupTaskEntry('commonjs', ctx.runtime, {\n path: exp._path,\n source: exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:* tasks\n for (const exp of exports) {\n const output = exp.import\n\n if (!output) continue\n\n addRollupTaskEntry('esm', ctx.runtime, {\n path: exp._path,\n source: exp.source,\n output,\n })\n }\n\n // Parse rollup:commonjs:browser tasks\n for (const exp of exports) {\n const output = exp.browser?.require\n\n if (!output) continue\n\n addRollupTaskEntry('commonjs', 'browser', {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:browser tasks\n for (const exp of exports) {\n const output = exp.browser?.import\n\n if (!output) continue\n\n addRollupTaskEntry('esm', 'browser', {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output,\n })\n }\n\n for (const bundle of bundles) {\n const idx = bundles.indexOf(bundle)\n\n if (bundle.require) {\n addRollupTaskEntry('commonjs', bundle.runtime || ctx.runtime, {\n path: `__$$bundle_cjs_${idx}$$__`,\n source: bundle.source,\n output: bundle.require,\n })\n }\n\n if (bundle.import) {\n addRollupTaskEntry('esm', bundle.runtime || ctx.runtime, {\n path: `__$$bundle_esm_${idx}$$__`,\n source: bundle.source,\n output: bundle.import,\n })\n }\n }\n\n // Perform rolldown dts tasks first, as they have special logic for removing non .d.ts chunks\n tasks.push(...Object.values(rolldownDtsTask))\n // Then run api-extractor tsdoc release tag checking (if rolldown is used for dts bundling, otherwise api-extractor performs both in the build:dts task)\n // @TODO\n // Then run rollup tasks\n tasks.push(...Object.values(rollupTasks))\n\n return tasks\n}\n"],"names":[],"mappings":";;AAQO,SAAS,kBAAkB,KAAgC;AAC1D,QAAA,EAAC,QAAQ,KAAK,OAAA,IAAU,KAExB,UAAU,QAAQ,WAAW,CAAA,GAE7B,QAAqB,IAErB,UAAU,OAAO,QAAQ,IAAI,WAAW,CAAE,CAAA,EAAE;AAAA,IAChD,CAAC,CAAC,OAAO,GAAG,OAAO,EAAC,OAAO,GAAG,IAAG;AAAA,KAG7B,UAAmB;AAAA,IACvB,MAAM;AAAA,IACN,SAAS,CAAA;AAAA,EAAC,GAGN,kBAAmD,IACnD,c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B,YAAY,OAAO,WAAW,IAAI,SAAS;AAAA,MAC5D,MAAM,kBAAkB,GAAG;AAAA,MAC3B,QAAQ,OAAO;AAAA,MACf,QAAQ,OAAO;AAAA,IAAA,CAChB,GAGC,OAAO,UACT,mBAAmB,OAAO,OAAO,WAAW,IAAI,SAAS;AAAA,MACvD,MAAM,kBAAkB,GAAG;AAAA,MAC3B,QAAQ,OAAO;AAAA,MACf,QAAQ,OAAO;AAAA,IAAA,CAChB;AAAA,EAAA;AAKL,SAAA,MAAM,KAAK,GAAG,OAAO,OAAO,eAAe,CAAC,GAI5C,MAAM,KAAK,GAAG,OAAO,OAAO,WAAW,CAAC,GAEjC;AACT;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveConfigProperty.js","sources":["../../src/node/core/config/resolveConfigProperty.ts"],"sourcesContent":["import type {PkgConfigProperty, PkgConfigPropertyResolver} from './types'\n\n/** @internal */\nexport function resolveConfigProperty<T>(\n prop: PkgConfigProperty<T> | undefined,\n initialValue: T,\n): T {\n if (!prop) return initialValue\n\n if (typeof prop === 'function') {\n return (prop as PkgConfigPropertyResolver<T>)(initialValue)\n }\n\n return prop\n}\n"],"names":[],"mappings":"AAGgB,SAAA,sBACd,MACA,cACG;AACH,SAAK,OAED,OAAO,QAAS,aACV,KAAsC,YAAY,IAGrD,OANW;AAOpB;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { dts } from "rolldown-plugin-dts";
|
|
3
|
-
import { pkgExtMap } from "./
|
|
3
|
+
import { pkgExtMap } from "./index.js";
|
|
4
4
|
function resolveRolldownConfig(ctx, buildTask) {
|
|
5
5
|
const { format, runtime, target } = buildTask, { config, cwd, exports: _exports, external, distPath, logger, pkg, ts } = ctx, outputExt = pkgExtMap[pkg.type || "commonjs"][format], outDir = path.relative(cwd, distPath), pathAliases = Object.fromEntries(
|
|
6
6
|
Object.entries(ts.config?.options.paths || {}).map(([key, val]) => [key, path.resolve(cwd, ts.config?.options.baseUrl || ".", val[0])])
|