@sanity/pkg-utils 5.1.2 → 5.1.3
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 +1 -1
- package/dist/_chunks-cjs/build.cjs +36 -16
- package/dist/_chunks-cjs/build.cjs.map +1 -1
- package/dist/_chunks-cjs/check.cjs +4 -4
- package/dist/_chunks-cjs/check.cjs.map +1 -1
- package/dist/_chunks-cjs/consoleSpy.cjs +65 -40
- package/dist/_chunks-cjs/consoleSpy.cjs.map +1 -1
- package/dist/_chunks-cjs/handleError.cjs +3 -3
- package/dist/_chunks-cjs/index.cjs +77 -40
- package/dist/_chunks-cjs/index.cjs.map +1 -1
- package/dist/_chunks-cjs/init.cjs +3 -3
- package/dist/_chunks-cjs/logger.cjs +3 -3
- package/dist/_chunks-cjs/watch.cjs +8 -8
- package/dist/_chunks-cjs/watch.cjs.map +1 -1
- package/dist/cli.cjs +3 -3
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +21 -10
- package/dist/index.d.ts +21 -10
- package/dist/index.js +164 -84
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/node/build.ts +1 -3
- package/src/node/check.ts +2 -3
- package/src/node/core/contexts/buildContext.ts +4 -5
- package/src/node/core/pkg/parseExports.ts +35 -13
- package/src/node/core/pkg/pkgExt.ts +6 -19
- package/src/node/core/pkg/validateExports.ts +6 -5
- package/src/node/resolveBuildContext.ts +11 -11
- package/src/node/resolveBuildTasks.ts +49 -7
- package/src/node/tasks/dts/buildTypes.ts +5 -1
- package/src/node/tasks/dts/getTargetPaths.ts +6 -2
- package/src/node/tasks/index.ts +3 -2
- package/src/node/tasks/rollup/index.ts +1 -0
- package/src/node/tasks/rollup/resolveRollupConfig.ts +22 -31
- package/src/node/tasks/rollup/rollupLegacyTask.ts +144 -0
- package/src/node/tasks/rollup/rollupTask.ts +2 -2
- package/src/node/tasks/types.ts +16 -5
- package/src/node/watch.ts +3 -4
package/README.md
CHANGED
|
@@ -142,7 +142,7 @@ The name of the library from which to import JSX factory and fragment names.
|
|
|
142
142
|
- Default: `false`
|
|
143
143
|
|
|
144
144
|
Build package with support for legacy exports (writes root `<export>.js` files). Use this if you
|
|
145
|
-
need to support older
|
|
145
|
+
need to support older bundlers.
|
|
146
146
|
|
|
147
147
|
#### `minify`
|
|
148
148
|
|
|
@@ -8,18 +8,18 @@ require("mkdirp");
|
|
|
8
8
|
var path = require("path");
|
|
9
9
|
require("prompts");
|
|
10
10
|
require("typescript");
|
|
11
|
-
var fs = require("fs"),
|
|
12
|
-
function
|
|
13
|
-
return e &&
|
|
11
|
+
var fs = require("fs"), chalk = require("chalk"), index = require("./index.cjs");
|
|
12
|
+
function _interopDefault(e) {
|
|
13
|
+
return e && e.__esModule ? e : { default: e };
|
|
14
14
|
}
|
|
15
|
-
var path__default = /* @__PURE__ */
|
|
15
|
+
var path__default = /* @__PURE__ */ _interopDefault(path), fs__default = /* @__PURE__ */ _interopDefault(fs), chalk__default = /* @__PURE__ */ _interopDefault(chalk);
|
|
16
16
|
function resolveBuildTasks(ctx) {
|
|
17
17
|
const { config, cwd, pkg, target } = ctx, bundles = config?.bundles || [], tasks = [], exports2 = Object.entries(ctx.exports || {}).map(
|
|
18
18
|
([_path, exp]) => ({ _path, ...exp })
|
|
19
19
|
), dtsTask = {
|
|
20
20
|
type: "build:dts",
|
|
21
21
|
entries: []
|
|
22
|
-
}, rollupTasks = {};
|
|
22
|
+
}, rollupTasks = {}, rollupLegacyTasks = {};
|
|
23
23
|
function addRollupTaskEntry(format, runtime, entry) {
|
|
24
24
|
const buildId = `${format}:${runtime}`;
|
|
25
25
|
rollupTasks[buildId] ? rollupTasks[buildId].entries.push(entry) : rollupTasks[buildId] = {
|
|
@@ -31,23 +31,35 @@ function resolveBuildTasks(ctx) {
|
|
|
31
31
|
target: target[runtime]
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
+
function addRollupLegacyTaskEntry(runtime, entry) {
|
|
35
|
+
const buildId = `esm:${runtime}`;
|
|
36
|
+
rollupLegacyTasks[buildId] ? rollupLegacyTasks[buildId].entries.push(entry) : rollupLegacyTasks[buildId] = {
|
|
37
|
+
type: "build:legacy",
|
|
38
|
+
buildId,
|
|
39
|
+
entries: [entry],
|
|
40
|
+
runtime,
|
|
41
|
+
format: "esm",
|
|
42
|
+
// @TODO set a different target here that is compatible with legacy bundlers and testing tools like brownfield jest
|
|
43
|
+
target: target[runtime]
|
|
44
|
+
};
|
|
45
|
+
}
|
|
34
46
|
for (const exp of exports2) {
|
|
35
47
|
const importId = path__default.default.join(pkg.name, exp._path);
|
|
36
48
|
exp.source?.endsWith(".ts") && dtsTask.entries.push({
|
|
37
49
|
importId,
|
|
38
50
|
exportPath: exp._path,
|
|
39
51
|
sourcePath: exp.source,
|
|
40
|
-
targetPaths:
|
|
52
|
+
targetPaths: consoleSpy.getTargetPaths(pkg.type, exp)
|
|
41
53
|
}), exp.browser?.source?.endsWith(".ts") && dtsTask.entries.push({
|
|
42
54
|
importId,
|
|
43
55
|
exportPath: exp._path,
|
|
44
56
|
sourcePath: exp.browser.source,
|
|
45
|
-
targetPaths:
|
|
57
|
+
targetPaths: consoleSpy.getTargetPaths(pkg.type, exp.browser)
|
|
46
58
|
}), exp.node?.source?.endsWith(".ts") && dtsTask.entries.push({
|
|
47
59
|
importId,
|
|
48
60
|
exportPath: exp._path,
|
|
49
61
|
sourcePath: exp.node.source,
|
|
50
|
-
targetPaths:
|
|
62
|
+
targetPaths: consoleSpy.getTargetPaths(pkg.type, exp.node)
|
|
51
63
|
});
|
|
52
64
|
}
|
|
53
65
|
for (const bundle of bundles)
|
|
@@ -57,7 +69,7 @@ function resolveBuildTasks(ctx) {
|
|
|
57
69
|
importId,
|
|
58
70
|
exportPath,
|
|
59
71
|
sourcePath: bundle.source,
|
|
60
|
-
targetPaths:
|
|
72
|
+
targetPaths: consoleSpy.getTargetPaths(pkg.type, bundle)
|
|
61
73
|
});
|
|
62
74
|
}
|
|
63
75
|
if (dtsTask.entries.length && tasks.push(dtsTask), !ctx.emitDeclarationOnly) {
|
|
@@ -93,6 +105,18 @@ function resolveBuildTasks(ctx) {
|
|
|
93
105
|
output
|
|
94
106
|
});
|
|
95
107
|
}
|
|
108
|
+
if (config?.legacyExports)
|
|
109
|
+
for (const exp of exports2) {
|
|
110
|
+
const runtime = exp.browser?.import || exp.browser?.require ? "browser" : ctx.runtime, output = exp.browser?.import || exp.import || exp.browser?.require || exp.require;
|
|
111
|
+
if (!output)
|
|
112
|
+
continue;
|
|
113
|
+
const legacyOutput = output.replace(consoleSpy.fileEnding, consoleSpy.legacyEnding);
|
|
114
|
+
addRollupLegacyTaskEntry(runtime, {
|
|
115
|
+
path: exp._path,
|
|
116
|
+
source: exp.browser?.source || exp.source,
|
|
117
|
+
output: legacyOutput
|
|
118
|
+
});
|
|
119
|
+
}
|
|
96
120
|
for (const bundle of bundles) {
|
|
97
121
|
const idx = bundles.indexOf(bundle);
|
|
98
122
|
bundle.require && addRollupTaskEntry("commonjs", bundle.runtime || ctx.runtime, {
|
|
@@ -105,13 +129,10 @@ function resolveBuildTasks(ctx) {
|
|
|
105
129
|
output: bundle.import
|
|
106
130
|
});
|
|
107
131
|
}
|
|
108
|
-
if (tasks.push(...Object.values(rollupTasks)), config?.legacyExports) {
|
|
132
|
+
if (tasks.push(...Object.values(rollupTasks), ...Object.values(rollupLegacyTasks)), config?.legacyExports) {
|
|
109
133
|
for (const exp of exports2)
|
|
110
134
|
if (exp._exported && exp._path !== ".") {
|
|
111
|
-
const relativeTargetPath = (exp.browser?.import || exp.import || "").replace(
|
|
112
|
-
/\.[^/.]+$/,
|
|
113
|
-
""
|
|
114
|
-
);
|
|
135
|
+
const relativeTargetPath = (exp.browser?.import || exp.import || exp.browser?.require || exp.require || "").replace(consoleSpy.fileEnding, consoleSpy.legacyEnding).replace(/\.[^/.]+$/, "");
|
|
115
136
|
relativeTargetPath && fs__default.default.writeFileSync(
|
|
116
137
|
path__default.default.resolve(cwd, `${exp._path}.js`),
|
|
117
138
|
["// AUTO-GENERATED \u2013 DO NOT EDIT", `export * from '${relativeTargetPath}'`, ""].join(
|
|
@@ -136,11 +157,10 @@ function createSpinner(msg) {
|
|
|
136
157
|
};
|
|
137
158
|
}
|
|
138
159
|
async function build(options) {
|
|
139
|
-
const { cwd, emitDeclarationOnly, strict = !1, tsconfig: tsconfigOption } = options, logger$1 = logger.createLogger(), pkg = await consoleSpy.loadPkgWithReporting({ cwd, logger: logger$1, strict }), config = await consoleSpy.loadConfig({ cwd }),
|
|
160
|
+
const { cwd, emitDeclarationOnly, strict = !1, tsconfig: tsconfigOption } = options, logger$1 = logger.createLogger(), pkg = await consoleSpy.loadPkgWithReporting({ cwd, logger: logger$1, strict }), config = await consoleSpy.loadConfig({ cwd }), tsconfig = tsconfigOption || config?.tsconfig || "tsconfig.json", ctx = await consoleSpy.resolveBuildContext({
|
|
140
161
|
config,
|
|
141
162
|
cwd,
|
|
142
163
|
emitDeclarationOnly,
|
|
143
|
-
extMap,
|
|
144
164
|
logger: logger$1,
|
|
145
165
|
pkg,
|
|
146
166
|
strict,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.cjs","sources":["../../src/node/resolveBuildTasks.ts","../../src/node/spinner.ts","../../src/node/build.ts"],"sourcesContent":["import fs from 'fs'\nimport path from 'path'\n\nimport type {BuildContext, PkgExport, PkgFormat, PkgRuntime} from './core'\nimport type {BuildTask, DtsTask, RollupTask, RollupTaskEntry} from './tasks'\nimport {getTargetPaths} from './tasks/dts/getTargetPaths'\n\n/** @internal */\nexport function resolveBuildTasks(ctx: BuildContext): BuildTask[] {\n const {config, cwd, 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 rollupTasks: Record<string, RollupTask> = {}\n\n function addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: RollupTaskEntry) {\n const buildId = `${format}:${runtime}`\n\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 // 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 if (!ctx.emitDeclarationOnly) {\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 tasks.push(...Object.values(rollupTasks))\n\n // Write legacy exports files\n if (config?.legacyExports) {\n for (const exp of exports) {\n if (exp._exported && exp._path !== '.') {\n const relativeTargetPath = (exp.browser?.import || exp.import || '').replace(\n /\\.[^/.]+$/,\n '',\n )\n\n if (relativeTargetPath) {\n fs.writeFileSync(\n path.resolve(cwd, `${exp._path}.js`),\n ['// AUTO-GENERATED – DO NOT EDIT', `export * from '${relativeTargetPath}'`, ''].join(\n '\\n',\n ),\n )\n }\n }\n }\n }\n }\n\n return tasks\n}\n","/* eslint-disable no-console */\n\nimport chalk from 'chalk'\n\nexport function createSpinner(msg: string): {complete: () => void; error: () => void} {\n const startTime = Date.now()\n\n console.log(msg)\n\n return {\n complete: () => {\n console.log(`${chalk.green('[success]')} ${chalk.gray(`${Date.now() - startTime}ms`)}`)\n },\n error: () => {\n console.log(`${chalk.red(`[error]`)} ${chalk.gray(`${Date.now() - startTime}ms`)}`)\n },\n }\n}\n","import {getPkgExtMap, loadConfig, loadPkgWithReporting} from './core'\nimport {createLogger} from './logger'\nimport {resolveBuildContext} from './resolveBuildContext'\nimport {resolveBuildTasks} from './resolveBuildTasks'\nimport {createSpinner} from './spinner'\nimport {type BuildTask, buildTaskHandlers, type TaskHandler} from './tasks'\n\n/**\n * Build the distribution files of a npm package.\n *\n * @example\n * ```ts\n * import {build} from '@sanity/pkg-utils'\n *\n * build({\n * cwd: process.cwd(),\n * tsconfig: 'tsconfig.dist.json,\n * }).then(() => {\n * console.log('successfully built')\n * }).catch((err) => {\n * console.log(`build error: ${err.message}`)\n * })\n * ```\n *\n * @public\n */\nexport async function build(options: {\n cwd: string\n emitDeclarationOnly?: boolean\n strict?: boolean\n tsconfig?: string\n}): Promise<void> {\n const {cwd, emitDeclarationOnly, strict = false, tsconfig: tsconfigOption} = options\n const logger = createLogger()\n\n const pkg = await loadPkgWithReporting({cwd, logger, strict})\n\n const config = await loadConfig({cwd})\n const extMap = getPkgExtMap({legacyExports: config?.legacyExports ?? false})\n const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'\n\n const ctx = await resolveBuildContext({\n config,\n cwd,\n emitDeclarationOnly,\n extMap,\n logger,\n pkg,\n strict,\n tsconfig,\n })\n\n const buildTasks = resolveBuildTasks(ctx)\n\n for (const task of buildTasks) {\n const handler = buildTaskHandlers[task.type] as TaskHandler<BuildTask>\n const taskName = handler.name(ctx, task)\n\n const spinner = createSpinner(taskName)\n\n try {\n const result = await handler.exec(ctx, task).toPromise()\n\n spinner.complete()\n ctx.logger.log()\n\n handler.complete(ctx, task, result)\n } catch (err) {\n spinner.error()\n\n if (err instanceof Error) {\n const RE_CWD = new RegExp(`${cwd}`, 'g')\n\n ctx.logger.error(err.message.replace(RE_CWD, '.'))\n ctx.logger.log()\n }\n\n handler.error(ctx, task, err)\n\n process.exit(1)\n }\n }\n}\n"],"names":["exports","path","getTargetPaths","fs","chalk","logger","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,"file":"build.cjs","sources":["../../src/node/resolveBuildTasks.ts","../../src/node/spinner.ts","../../src/node/build.ts"],"sourcesContent":["import fs from 'fs'\nimport path from 'path'\n\nimport type {BuildContext, PkgExport, PkgFormat, PkgRuntime} from './core'\nimport type {BuildTask, DtsTask, RollupLegacyTask, RollupTask, RollupTaskEntry} from './tasks'\nimport {fileEnding, getTargetPaths, legacyEnding} from './tasks/dts/getTargetPaths'\n\n/** @internal */\nexport function resolveBuildTasks(ctx: BuildContext): BuildTask[] {\n const {config, cwd, 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 rollupTasks: Record<string, RollupTask> = {}\n const rollupLegacyTasks: Record<string, RollupLegacyTask> = {}\n\n function addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: RollupTaskEntry) {\n const buildId = `${format}:${runtime}`\n\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 function addRollupLegacyTaskEntry(runtime: PkgRuntime, entry: RollupTaskEntry) {\n const buildId = `esm:${runtime}`\n\n if (rollupLegacyTasks[buildId]) {\n rollupLegacyTasks[buildId].entries.push(entry)\n } else {\n rollupLegacyTasks[buildId] = {\n type: 'build:legacy',\n buildId,\n entries: [entry],\n runtime,\n format: 'esm',\n // @TODO set a different target here that is compatible with legacy bundlers and testing tools like brownfield jest\n target: target[runtime],\n }\n }\n }\n\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 if (!ctx.emitDeclarationOnly) {\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 // Create rollup bundles that legacy export files will re-export\n if (config?.legacyExports) {\n for (const exp of exports) {\n const runtime = exp.browser?.import || exp.browser?.require ? 'browser' : ctx.runtime\n const output = exp.browser?.import || exp.import || exp.browser?.require || exp.require\n\n if (!output) continue\n\n // Change the suffix to what the legacy exports will use\n const legacyOutput = output.replace(fileEnding, legacyEnding)\n\n addRollupLegacyTaskEntry(runtime, {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output: legacyOutput,\n })\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 tasks.push(...Object.values(rollupTasks), ...Object.values(rollupLegacyTasks))\n\n // Write legacy exports files\n if (config?.legacyExports) {\n for (const exp of exports) {\n if (exp._exported && exp._path !== '.') {\n const output = (\n exp.browser?.import ||\n exp.import ||\n exp.browser?.require ||\n exp.require ||\n ''\n ).replace(fileEnding, legacyEnding)\n const relativeTargetPath = output.replace(/\\.[^/.]+$/, '')\n\n if (relativeTargetPath) {\n fs.writeFileSync(\n path.resolve(cwd, `${exp._path}.js`),\n ['// AUTO-GENERATED – DO NOT EDIT', `export * from '${relativeTargetPath}'`, ''].join(\n '\\n',\n ),\n )\n }\n }\n }\n }\n }\n\n return tasks\n}\n","/* eslint-disable no-console */\n\nimport chalk from 'chalk'\n\nexport function createSpinner(msg: string): {complete: () => void; error: () => void} {\n const startTime = Date.now()\n\n console.log(msg)\n\n return {\n complete: () => {\n console.log(`${chalk.green('[success]')} ${chalk.gray(`${Date.now() - startTime}ms`)}`)\n },\n error: () => {\n console.log(`${chalk.red(`[error]`)} ${chalk.gray(`${Date.now() - startTime}ms`)}`)\n },\n }\n}\n","import {loadConfig, loadPkgWithReporting} from './core'\nimport {createLogger} from './logger'\nimport {resolveBuildContext} from './resolveBuildContext'\nimport {resolveBuildTasks} from './resolveBuildTasks'\nimport {createSpinner} from './spinner'\nimport {type BuildTask, buildTaskHandlers, type TaskHandler} from './tasks'\n\n/**\n * Build the distribution files of a npm package.\n *\n * @example\n * ```ts\n * import {build} from '@sanity/pkg-utils'\n *\n * build({\n * cwd: process.cwd(),\n * tsconfig: 'tsconfig.dist.json,\n * }).then(() => {\n * console.log('successfully built')\n * }).catch((err) => {\n * console.log(`build error: ${err.message}`)\n * })\n * ```\n *\n * @public\n */\nexport async function build(options: {\n cwd: string\n emitDeclarationOnly?: boolean\n strict?: boolean\n tsconfig?: string\n}): Promise<void> {\n const {cwd, emitDeclarationOnly, strict = false, tsconfig: tsconfigOption} = options\n const logger = createLogger()\n\n const pkg = await loadPkgWithReporting({cwd, logger, strict})\n\n const config = await loadConfig({cwd})\n const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'\n\n const ctx = await resolveBuildContext({\n config,\n cwd,\n emitDeclarationOnly,\n logger,\n pkg,\n strict,\n tsconfig,\n })\n\n const buildTasks = resolveBuildTasks(ctx)\n\n for (const task of buildTasks) {\n const handler = buildTaskHandlers[task.type] as TaskHandler<BuildTask>\n const taskName = handler.name(ctx, task)\n\n const spinner = createSpinner(taskName)\n\n try {\n const result = await handler.exec(ctx, task).toPromise()\n\n spinner.complete()\n ctx.logger.log()\n\n handler.complete(ctx, task, result)\n } catch (err) {\n spinner.error()\n\n if (err instanceof Error) {\n const RE_CWD = new RegExp(`${cwd}`, 'g')\n\n ctx.logger.error(err.message.replace(RE_CWD, '.'))\n ctx.logger.log()\n }\n\n handler.error(ctx, task, err)\n\n process.exit(1)\n }\n }\n}\n"],"names":["exports","path","getTargetPaths","fileEnding","legacyEnding","fs","chalk","logger","createLogger","loadPkgWithReporting","loadConfig","resolveBuildContext","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;AAAA,IAAA,QACAJ;AAAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAA,GAEK,aAAa,kBAAkB,GAAG;AAExC,aAAW,QAAQ,YAAY;AAC7B,UAAM,UAAUK,MAAA,kBAAkB,KAAK,IAAI,GACrC,WAAW,QAAQ,KAAK,KAAK,IAAI,GAEjC,UAAU,cAAc,QAAQ;AAElC,QAAA;AACF,YAAM,SAAS,MAAM,QAAQ,KAAK,KAAK,IAAI,EAAE;AAErC,cAAA,SAAA,GACR,IAAI,OAAO,IAAA,GAEX,QAAQ,SAAS,KAAK,MAAM,MAAM;AAAA,aAC3B,KAAK;AAGZ,UAFA,QAAQ,SAEJ,eAAe,OAAO;AACxB,cAAM,SAAS,IAAI,OAAO,GAAG,GAAG,IAAI,GAAG;AAEnC,YAAA,OAAO,MAAM,IAAI,QAAQ,QAAQ,QAAQ,GAAG,CAAC,GACjD,IAAI,OAAO,IAAI;AAAA,MACjB;AAEA,cAAQ,MAAM,KAAK,MAAM,GAAG,GAE5B,QAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AACF;;;"}
|
|
@@ -8,10 +8,10 @@ require("mkdirp");
|
|
|
8
8
|
require("prompts");
|
|
9
9
|
require("typescript");
|
|
10
10
|
var chalk = require("chalk"), treeify = require("treeify"), fs = require("fs"), prettyBytes = require("pretty-bytes");
|
|
11
|
-
function
|
|
12
|
-
return e &&
|
|
11
|
+
function _interopDefault(e) {
|
|
12
|
+
return e && e.__esModule ? e : { default: e };
|
|
13
13
|
}
|
|
14
|
-
var esbuild__default = /* @__PURE__ */
|
|
14
|
+
var esbuild__default = /* @__PURE__ */ _interopDefault(esbuild), path__default = /* @__PURE__ */ _interopDefault(path), chalk__default = /* @__PURE__ */ _interopDefault(chalk), treeify__default = /* @__PURE__ */ _interopDefault(treeify), prettyBytes__default = /* @__PURE__ */ _interopDefault(prettyBytes);
|
|
15
15
|
function getFilesize(file) {
|
|
16
16
|
const stats = fs.statSync(file);
|
|
17
17
|
return prettyBytes__default.default(stats.size);
|
|
@@ -48,7 +48,7 @@ function printPackageTree(ctx) {
|
|
|
48
48
|
), logger2.log(treeify__default.default.asTree(tree, !0, !0));
|
|
49
49
|
}
|
|
50
50
|
async function check(options) {
|
|
51
|
-
const { cwd, strict = !1, tsconfig: tsconfigOption } = options, logger$1 = logger.createLogger(), pkg = await consoleSpy.loadPkgWithReporting({ cwd, logger: logger$1, strict }), config = await consoleSpy.loadConfig({ cwd }),
|
|
51
|
+
const { cwd, strict = !1, tsconfig: tsconfigOption } = options, logger$1 = logger.createLogger(), pkg = await consoleSpy.loadPkgWithReporting({ cwd, logger: logger$1, strict }), config = await consoleSpy.loadConfig({ cwd }), tsconfig = tsconfigOption || config?.tsconfig || "tsconfig.json", ctx = await consoleSpy.resolveBuildContext({ config, cwd, logger: logger$1, pkg, strict, tsconfig });
|
|
52
52
|
if (printPackageTree(ctx), strict) {
|
|
53
53
|
const missingFiles = [];
|
|
54
54
|
for (const [, exp] of Object.entries(ctx.exports || {}))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.cjs","sources":["../../src/node/getFilesize.ts","../../src/node/printPackageTree.ts","../../src/node/check.ts"],"sourcesContent":["import {statSync} from '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 chalk from 'chalk'\nimport path from 'path'\nimport treeify from 'treeify'\n\nimport {BuildContext, PkgExport} from './core'\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\n logger.log(treeify.asTree(tree as Record<string, any>, true, true))\n}\n","import esbuild, {type BuildFailure} from 'esbuild'\nimport path from 'path'\n\nimport {createConsoleSpy} from './consoleSpy'\nimport {getPkgExtMap, loadConfig, loadPkgWithReporting} from './core'\nimport {fileExists} from './fileExists'\nimport {createLogger, type Logger} from './logger'\nimport {printPackageTree} from './printPackageTree'\nimport {resolveBuildContext} from './resolveBuildContext'\n\n/** @public */\nexport async function check(options: {\n cwd: string\n strict?: boolean\n tsconfig?: string\n}): Promise<void> {\n const {cwd, strict = false, tsconfig: tsconfigOption} = options\n const logger = createLogger()\n\n const pkg = await loadPkgWithReporting({cwd, logger, strict})\n const config = await loadConfig({cwd})\n const extMap = getPkgExtMap({legacyExports: config?.legacyExports ?? false})\n const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'\n const ctx = await resolveBuildContext({config, cwd, extMap, logger, pkg, strict, tsconfig})\n\n printPackageTree(ctx)\n\n if (strict) {\n const missingFiles: string[] = []\n\n // Check if there are missing files\n for (const [, exp] of Object.entries(ctx.exports || {})) {\n if (exp.source && !fileExists(path.resolve(cwd, exp.source))) {\n missingFiles.push(exp.source)\n }\n\n if (exp.require && !fileExists(path.resolve(cwd, exp.require))) {\n missingFiles.push(exp.require)\n }\n\n if (exp.import && !fileExists(path.resolve(cwd, exp.import))) {\n missingFiles.push(exp.import)\n }\n }\n\n if (ctx.pkg.types && !fileExists(path.resolve(cwd, ctx.pkg.types))) {\n missingFiles.push(ctx.pkg.types)\n }\n\n if (missingFiles.length) {\n logger.error(`missing files: ${missingFiles.join(', ')}`)\n process.exit(1)\n }\n\n // Check if the files are resolved\n const exportPaths: {require: string[]; import: string[]} = {\n require: [],\n import: [],\n }\n\n for (const exp of Object.values(ctx.exports || {})) {\n if (!exp._exported) continue\n if (exp.require) exportPaths.require.push(exp.require)\n if (exp.import) exportPaths.import.push(exp.import)\n }\n\n const external = [\n ...Object.keys(pkg.dependencies || {}),\n ...Object.keys(pkg.devDependencies || {}),\n ]\n\n const consoleSpy = createConsoleSpy()\n\n if (exportPaths.import.length) {\n checkExports(exportPaths.import, {cwd, external, format: 'esm', logger})\n }\n\n if (exportPaths.require.length) {\n checkExports(exportPaths.require, {cwd, external, format: 'cjs', logger})\n }\n\n consoleSpy.restore()\n }\n}\n\nasync function checkExports(\n exportPaths: string[],\n options: {cwd: string; external: string[]; format: 'esm' | 'cjs'; logger: Logger},\n) {\n const {cwd, external, format, logger} = options\n\n const code = exportPaths\n .map((id) => (format ? `import('${id}');` : `require('${id}');`))\n .join('\\n')\n\n try {\n const esbuildResult = await esbuild.build({\n bundle: true,\n external,\n format,\n logLevel: 'silent',\n // otherwise output maps to stdout as we're using stdin\n outfile: '/dev/null',\n platform: 'node',\n stdin: {\n contents: code,\n loader: 'js',\n resolveDir: cwd,\n },\n })\n\n if (esbuildResult.errors.length > 0) {\n for (const msg of esbuildResult.errors) {\n printEsbuildMessage(logger.warn, msg)\n\n logger.log()\n }\n\n process.exit(1)\n }\n\n const esbuildWarnings = esbuildResult.warnings.filter((msg) => {\n !(msg.detail || msg.text).includes(`does not affect esbuild's own target setting`)\n })\n\n for (const msg of esbuildWarnings) {\n printEsbuildMessage(logger.warn, msg)\n\n logger.log()\n }\n } catch (err) {\n const {errors} = err as BuildFailure\n\n for (const msg of errors) {\n printEsbuildMessage(logger.error, msg)\n\n logger.log()\n }\n\n process.exit(1)\n }\n}\n\nfunction printEsbuildMessage(log: (...args: unknown[]) => void, msg: esbuild.Message) {\n if (msg.location) {\n log(\n [\n `${msg.detail || msg.text}\\n`,\n `${msg.location.line} | ${msg.location.lineText}\\n`,\n `in ./${msg.location.file}:${msg.location.line}:${msg.location.column}`,\n ].join(''),\n )\n } else {\n log(msg.detail || msg.text)\n }\n}\n"],"names":["statSync","prettyBytes","path","fileExists","exports","logger","chalk","treeify","createLogger","loadPkgWithReporting","loadConfig","getPkgExtMap","resolveBuildContext","consoleSpy","createConsoleSpy","esbuild"],"mappings":";;;;;;;;;;;;;;AAGO,SAAS,YAAY,MAAsB;AAC1C,QAAA,QAAQA,YAAS,IAAI;AAEpB,SAAAC,qBAAA,QAAY,MAAM,IAAI;AAC/B;ACCA,SAAS,YAAY,KAAa,UAAkB;AAClD,QAAM,IAAIC,cAAAA,QAAK,QAAQ,KAAK,QAAQ,GAC9B,SAASC,OAAAA,WAAW,CAAC,GACrB,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I,IAAI;AAE9B;;"}
|
|
1
|
+
{"version":3,"file":"check.cjs","sources":["../../src/node/getFilesize.ts","../../src/node/printPackageTree.ts","../../src/node/check.ts"],"sourcesContent":["import {statSync} from '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 chalk from 'chalk'\nimport path from 'path'\nimport treeify from 'treeify'\n\nimport {BuildContext, PkgExport} from './core'\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\n logger.log(treeify.asTree(tree as Record<string, any>, true, true))\n}\n","import esbuild, {type BuildFailure} from 'esbuild'\nimport path from 'path'\n\nimport {createConsoleSpy} from './consoleSpy'\nimport {loadConfig, loadPkgWithReporting} from './core'\nimport {fileExists} from './fileExists'\nimport {createLogger, type Logger} from './logger'\nimport {printPackageTree} from './printPackageTree'\nimport {resolveBuildContext} from './resolveBuildContext'\n\n/** @public */\nexport async function check(options: {\n cwd: string\n strict?: boolean\n tsconfig?: string\n}): Promise<void> {\n const {cwd, strict = false, tsconfig: tsconfigOption} = options\n const logger = createLogger()\n\n const pkg = await loadPkgWithReporting({cwd, logger, strict})\n const config = await loadConfig({cwd})\n const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'\n const ctx = await resolveBuildContext({config, cwd, logger, pkg, strict, tsconfig})\n\n printPackageTree(ctx)\n\n if (strict) {\n const missingFiles: string[] = []\n\n // Check if there are missing files\n for (const [, exp] of Object.entries(ctx.exports || {})) {\n if (exp.source && !fileExists(path.resolve(cwd, exp.source))) {\n missingFiles.push(exp.source)\n }\n\n if (exp.require && !fileExists(path.resolve(cwd, exp.require))) {\n missingFiles.push(exp.require)\n }\n\n if (exp.import && !fileExists(path.resolve(cwd, exp.import))) {\n missingFiles.push(exp.import)\n }\n }\n\n if (ctx.pkg.types && !fileExists(path.resolve(cwd, ctx.pkg.types))) {\n missingFiles.push(ctx.pkg.types)\n }\n\n if (missingFiles.length) {\n logger.error(`missing files: ${missingFiles.join(', ')}`)\n process.exit(1)\n }\n\n // Check if the files are resolved\n const exportPaths: {require: string[]; import: string[]} = {\n require: [],\n import: [],\n }\n\n for (const exp of Object.values(ctx.exports || {})) {\n if (!exp._exported) continue\n if (exp.require) exportPaths.require.push(exp.require)\n if (exp.import) exportPaths.import.push(exp.import)\n }\n\n const external = [\n ...Object.keys(pkg.dependencies || {}),\n ...Object.keys(pkg.devDependencies || {}),\n ]\n\n const consoleSpy = createConsoleSpy()\n\n if (exportPaths.import.length) {\n checkExports(exportPaths.import, {cwd, external, format: 'esm', logger})\n }\n\n if (exportPaths.require.length) {\n checkExports(exportPaths.require, {cwd, external, format: 'cjs', logger})\n }\n\n consoleSpy.restore()\n }\n}\n\nasync function checkExports(\n exportPaths: string[],\n options: {cwd: string; external: string[]; format: 'esm' | 'cjs'; logger: Logger},\n) {\n const {cwd, external, format, logger} = options\n\n const code = exportPaths\n .map((id) => (format ? `import('${id}');` : `require('${id}');`))\n .join('\\n')\n\n try {\n const esbuildResult = await esbuild.build({\n bundle: true,\n external,\n format,\n logLevel: 'silent',\n // otherwise output maps to stdout as we're using stdin\n outfile: '/dev/null',\n platform: 'node',\n stdin: {\n contents: code,\n loader: 'js',\n resolveDir: cwd,\n },\n })\n\n if (esbuildResult.errors.length > 0) {\n for (const msg of esbuildResult.errors) {\n printEsbuildMessage(logger.warn, msg)\n\n logger.log()\n }\n\n process.exit(1)\n }\n\n const esbuildWarnings = esbuildResult.warnings.filter((msg) => {\n !(msg.detail || msg.text).includes(`does not affect esbuild's own target setting`)\n })\n\n for (const msg of esbuildWarnings) {\n printEsbuildMessage(logger.warn, msg)\n\n logger.log()\n }\n } catch (err) {\n const {errors} = err as BuildFailure\n\n for (const msg of errors) {\n printEsbuildMessage(logger.error, msg)\n\n logger.log()\n }\n\n process.exit(1)\n }\n}\n\nfunction printEsbuildMessage(log: (...args: unknown[]) => void, msg: esbuild.Message) {\n if (msg.location) {\n log(\n [\n `${msg.detail || msg.text}\\n`,\n `${msg.location.line} | ${msg.location.lineText}\\n`,\n `in ./${msg.location.file}:${msg.location.line}:${msg.location.column}`,\n ].join(''),\n )\n } else {\n log(msg.detail || msg.text)\n }\n}\n"],"names":["statSync","prettyBytes","path","fileExists","exports","logger","chalk","treeify","createLogger","loadPkgWithReporting","loadConfig","resolveBuildContext","consoleSpy","createConsoleSpy","esbuild"],"mappings":";;;;;;;;;;;;;;AAGO,SAAS,YAAY,MAAsB;AAC1C,QAAA,QAAQA,YAAS,IAAI;AAEpB,SAAAC,qBAAA,QAAY,MAAM,IAAI;AAC/B;ACCA,SAAS,YAAY,KAAa,UAAkB;AAClD,QAAM,IAAIC,cAAAA,QAAK,QAAQ,KAAK,QAAQ,GAC9B,SAASC,OAAAA,WAAW,CAAC,GACrB,OAAO,SAAS,YAAY,CAAC,IAAI;AAEhC,SAAA,EAAC,QAAQ;AAClB;AAEO,SAAS,iBAAiB,KAAyB;AACxD,QAAM,EAAC,KAAK,SAAAC,UAAS,QAAAC,SAAQ,QAAO;AAEpC,MAAI,CAACD;AAAS;AAEd,EAAAC,QAAO,IAAI,GAAGC,eAAM,QAAA,KAAK,IAAI,IAAI,CAAC,IAAIA,eAAAA,QAAM,MAAM,IAAI,OAAO,CAAC,EAAE;AAGhE,QAAM,OAAgC,CAAA;AAElC,MAAI,SACN,KAAK,OAAOA,eAAM,QAAA,OAAO,IAAI,IAAI,IAG/B,IAAI,QACN,KAAK,MAAM,OAAO;AAAA,IAChB,OAAO,QAAQ,IAAI,GAAG,EAAE,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAACA,uBAAM,KAAK,IAAI,GAAG,SAAS,IAAI,CAAC,CAAC;AAAA,EAAA;AAIpF,WAAS,SAAS,MAAc;AACxB,UAAA,OAAO,YAAY,KAAK,IAAI;AAE7B,WAAA,KAAK,OAIH,GAAGA,uBAAM,OAAO,IAAI,CAAC,IAAIA,uBAAM,KAAK,K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AU,IAAA;AAEjB,eAAW,OAAO;AAChB,0BAAoBA,QAAO,OAAO,GAAG,GAErCA,QAAO;AAGT,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;AAEA,SAAS,oBAAoB,KAAmC,KAAsB;AAChF,MAAI,WACN;AAAA,IACE;AAAA,MACE,GAAG,IAAI,UAAU,IAAI,IAAI;AAAA;AAAA,MACzB,GAAG,IAAI,SAAS,IAAI,MAAM,IAAI,SAAS,QAAQ;AAAA;AAAA,MAC/C,QAAQ,IAAI,SAAS,IAAI,IAAI,IAAI,SAAS,IAAI,IAAI,IAAI,SAAS,MAAM;AAAA,IAAA,EACrE,KAAK,EAAE;AAAA,EAGX,IAAA,IAAI,IAAI,UAAU,IAAI,IAAI;AAE9B;;"}
|
|
@@ -5,10 +5,10 @@ var config = require("@sanity/browserslist-config");
|
|
|
5
5
|
require("mkdirp");
|
|
6
6
|
require("prompts");
|
|
7
7
|
var ts = require("typescript");
|
|
8
|
-
function
|
|
9
|
-
return e &&
|
|
8
|
+
function _interopDefault(e) {
|
|
9
|
+
return e && e.__esModule ? e : { default: e };
|
|
10
10
|
}
|
|
11
|
-
var path__default = /* @__PURE__ */
|
|
11
|
+
var path__default = /* @__PURE__ */ _interopDefault(path), pkgUp__default = /* @__PURE__ */ _interopDefault(pkgUp), findConfig__default = /* @__PURE__ */ _interopDefault(findConfig), chalk__default = /* @__PURE__ */ _interopDefault(chalk), fs__default = /* @__PURE__ */ _interopDefault(fs), browserslist__default = /* @__PURE__ */ _interopDefault(browserslist), config__default = /* @__PURE__ */ _interopDefault(config), ts__default = /* @__PURE__ */ _interopDefault(ts);
|
|
12
12
|
const CONFIG_FILE_NAMES = [
|
|
13
13
|
"package.config.ts",
|
|
14
14
|
"package.config.js",
|
|
@@ -114,8 +114,41 @@ async function loadPkgWithReporting(options) {
|
|
|
114
114
|
function formatPath(segments) {
|
|
115
115
|
return segments.map((s, idx) => idx === 0 ? s : typeof s == "number" ? `[${s}]` : s.startsWith(".") ? `["${s}"]` : `.${s}`).join("");
|
|
116
116
|
}
|
|
117
|
+
const fileEnding = /\.[mc]?js$/, dtsEnding = ".d.ts", legacyEnding = ".esm.js", mtsEnding = ".d.mts", ctsEnding = ".d.cts";
|
|
118
|
+
function getTargetPaths(_type, expOrBundle) {
|
|
119
|
+
const type = _type === "module" ? "module" : "commonjs", set = /* @__PURE__ */ new Set();
|
|
120
|
+
return expOrBundle?.import && set.add(expOrBundle.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)), expOrBundle?.require && set.add(expOrBundle.require.replace(fileEnding, type === "commonjs" ? dtsEnding : ctsEnding)), isPkgExport(expOrBundle) && (expOrBundle.browser?.source || (expOrBundle.browser?.import && set.add(
|
|
121
|
+
expOrBundle.browser.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
|
|
122
|
+
), expOrBundle.browser?.require && set.add(
|
|
123
|
+
expOrBundle.browser.require.replace(
|
|
124
|
+
fileEnding,
|
|
125
|
+
type === "commonjs" ? dtsEnding : ctsEnding
|
|
126
|
+
)
|
|
127
|
+
)), expOrBundle.node?.source || (expOrBundle.node?.import && set.add(
|
|
128
|
+
expOrBundle.node.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)
|
|
129
|
+
), expOrBundle.node?.require && set.add(
|
|
130
|
+
expOrBundle.node.require.replace(fileEnding, type === "commonjs" ? dtsEnding : ctsEnding)
|
|
131
|
+
))), Array.from(set);
|
|
132
|
+
}
|
|
133
|
+
function isPkgExport(exp) {
|
|
134
|
+
return exp?.browser || exp?.node || exp?.default;
|
|
135
|
+
}
|
|
136
|
+
const pkgExtMap = {
|
|
137
|
+
// pkg.type: "commonjs"
|
|
138
|
+
commonjs: {
|
|
139
|
+
commonjs: ".js",
|
|
140
|
+
esm: ".mjs"
|
|
141
|
+
},
|
|
142
|
+
// pkg.type: "module"
|
|
143
|
+
module: {
|
|
144
|
+
commonjs: ".cjs",
|
|
145
|
+
esm: ".js"
|
|
146
|
+
},
|
|
147
|
+
// package.config.legacyExports: true
|
|
148
|
+
legacy: legacyEnding
|
|
149
|
+
};
|
|
117
150
|
function validateExports(_exports, options) {
|
|
118
|
-
const {
|
|
151
|
+
const { pkg } = options, ext = pkgExtMap[pkg.type || "commonjs"], errors = [];
|
|
119
152
|
for (const exp of _exports)
|
|
120
153
|
exp.require && !exp.require.endsWith(ext.commonjs) && errors.push(
|
|
121
154
|
`package.json with \`type: "${pkg.type}"\` - \`exports["${exp._path}"].require\` must end with "${ext.commonjs}"`
|
|
@@ -125,7 +158,7 @@ function validateExports(_exports, options) {
|
|
|
125
158
|
return errors;
|
|
126
159
|
}
|
|
127
160
|
function parseExports(options) {
|
|
128
|
-
const {
|
|
161
|
+
const { pkg, strict, legacyExports } = options, rootExport = {
|
|
129
162
|
_exported: !0,
|
|
130
163
|
_path: ".",
|
|
131
164
|
source: pkg.source || "",
|
|
@@ -138,24 +171,31 @@ function parseExports(options) {
|
|
|
138
171
|
import: pkg.module,
|
|
139
172
|
default: pkg.module || pkg.main || ""
|
|
140
173
|
}, extraExports = [], errors = [];
|
|
141
|
-
if (strict &&
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
strict && !pkg.exports["./package.json"] && errors.push('package.json: `exports["./package.json"] must be declared.');
|
|
174
|
+
if (strict && "typings" in pkg && errors.push("package.json: `typings` should be `types`"), pkg.exports) {
|
|
175
|
+
strict && !pkg.types && pkg.source?.endsWith(".ts") && errors.push(
|
|
176
|
+
"package.json: `types` must be declared for the npm listing to show as a TypeScript module."
|
|
177
|
+
), strict && !pkg.exports["./package.json"] && errors.push('package.json: `exports["./package.json"] must be declared.');
|
|
145
178
|
for (const [exportPath, exportEntry] of Object.entries(pkg.exports))
|
|
146
179
|
if (exportPath.endsWith(".json"))
|
|
147
180
|
exportPath === "./package.json" && exportEntry !== "./package.json" && errors.push('package.json: `exports["./package.json"] must be "./package.json".');
|
|
148
181
|
else if (!(logger.isRecord(exportEntry) && "svelte" in exportEntry))
|
|
149
182
|
if (logger.isRecord(exportEntry))
|
|
150
|
-
if (exportPath === ".")
|
|
151
|
-
exportEntry.require && rootExport.require && exportEntry.require !== rootExport.require && errors.push(
|
|
183
|
+
if (exportPath === ".") {
|
|
184
|
+
if (exportEntry.require && rootExport.require && exportEntry.require !== rootExport.require && errors.push(
|
|
152
185
|
'package.json: mismatch between "main" and "exports.require". These must be equal.'
|
|
153
|
-
),
|
|
154
|
-
|
|
155
|
-
|
|
186
|
+
), legacyExports) {
|
|
187
|
+
const indexLegacyExport = (exportEntry.browser?.import || exportEntry.import || exportEntry.browser?.require || exportEntry.require || "").replace(/(\.esm)?\.[mc]?js$/, legacyEnding);
|
|
188
|
+
indexLegacyExport !== rootExport.import && errors.push(
|
|
189
|
+
`package.json: "module" should be "${indexLegacyExport}" when "legacyExports" is true`
|
|
190
|
+
);
|
|
191
|
+
} else
|
|
192
|
+
exportEntry.import && rootExport.import && exportEntry.import !== rootExport.import && errors.push(
|
|
193
|
+
'package.json: mismatch between "module" and "exports.import" These must be equal.'
|
|
194
|
+
);
|
|
195
|
+
exportEntry.source && rootExport.source && exportEntry.source !== rootExport.source && errors.push(
|
|
156
196
|
'package.json: mismatch between "source" and "exports.source". These must be equal.'
|
|
157
197
|
), Object.assign(rootExport, exportEntry);
|
|
158
|
-
else {
|
|
198
|
+
} else {
|
|
159
199
|
const extraExport = {
|
|
160
200
|
_exported: !0,
|
|
161
201
|
_path: exportPath,
|
|
@@ -167,31 +207,12 @@ function parseExports(options) {
|
|
|
167
207
|
errors.push("package.json: exports must be an object");
|
|
168
208
|
}
|
|
169
209
|
const _exports = [rootExport, ...extraExports];
|
|
170
|
-
if (errors.push(...validateExports(_exports, {
|
|
210
|
+
if (errors.push(...validateExports(_exports, { pkg })), errors.length)
|
|
171
211
|
throw new Error(`
|
|
172
212
|
- ` + errors.join(`
|
|
173
213
|
- `));
|
|
174
214
|
return _exports;
|
|
175
215
|
}
|
|
176
|
-
const DEFAULT_PKG_EXT_MAP = {
|
|
177
|
-
// pkg.type: "commonjs"
|
|
178
|
-
commonjs: {
|
|
179
|
-
commonjs: ".js",
|
|
180
|
-
esm: ".mjs"
|
|
181
|
-
},
|
|
182
|
-
// pkg.type: "module"
|
|
183
|
-
module: {
|
|
184
|
-
commonjs: ".cjs",
|
|
185
|
-
esm: ".js"
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
function getPkgExtMap(options) {
|
|
189
|
-
const { legacyExports } = options, ret = { ...DEFAULT_PKG_EXT_MAP };
|
|
190
|
-
return legacyExports && (ret.commonjs = {
|
|
191
|
-
commonjs: ".js",
|
|
192
|
-
esm: ".esm.js"
|
|
193
|
-
}), ret;
|
|
194
|
-
}
|
|
195
216
|
async function loadTSConfig(options) {
|
|
196
217
|
const { cwd, tsconfigPath } = options, configPath = ts__default.default.findConfigFile(cwd, ts__default.default.sys.fileExists, tsconfigPath);
|
|
197
218
|
if (!configPath)
|
|
@@ -262,7 +283,6 @@ async function resolveBuildContext(options) {
|
|
|
262
283
|
config: config2,
|
|
263
284
|
cwd,
|
|
264
285
|
emitDeclarationOnly = !1,
|
|
265
|
-
extMap,
|
|
266
286
|
logger: logger2,
|
|
267
287
|
pkg,
|
|
268
288
|
strict,
|
|
@@ -285,7 +305,11 @@ async function resolveBuildContext(options) {
|
|
|
285
305
|
"*": webTarget.concat(nodeTarget),
|
|
286
306
|
browser: webTarget,
|
|
287
307
|
node: nodeTarget
|
|
288
|
-
}, parsedExports = parseExports({
|
|
308
|
+
}, parsedExports = parseExports({
|
|
309
|
+
pkg,
|
|
310
|
+
strict,
|
|
311
|
+
legacyExports: config2?.legacyExports ?? !1
|
|
312
|
+
}).reduce((acc, x) => {
|
|
289
313
|
const { _path: exportPath, ...exportEntry } = x;
|
|
290
314
|
return { ...acc, [exportPath]: exportEntry };
|
|
291
315
|
}, {}), exports2 = resolveConfigProperty(config2?.exports, parsedExports), parsedExternal = [
|
|
@@ -318,7 +342,6 @@ async function resolveBuildContext(options) {
|
|
|
318
342
|
emitDeclarationOnly,
|
|
319
343
|
exports: exports2,
|
|
320
344
|
external,
|
|
321
|
-
extMap,
|
|
322
345
|
files: [],
|
|
323
346
|
logger: logger2,
|
|
324
347
|
pkg,
|
|
@@ -345,14 +368,16 @@ function createConsoleSpy(options) {
|
|
|
345
368
|
};
|
|
346
369
|
}
|
|
347
370
|
exports.DEFAULT_BROWSERSLIST_QUERY = DEFAULT_BROWSERSLIST_QUERY;
|
|
348
|
-
exports.DEFAULT_PKG_EXT_MAP = DEFAULT_PKG_EXT_MAP;
|
|
349
371
|
exports.createConsoleSpy = createConsoleSpy;
|
|
350
|
-
exports.
|
|
372
|
+
exports.fileEnding = fileEnding;
|
|
373
|
+
exports.getTargetPaths = getTargetPaths;
|
|
374
|
+
exports.legacyEnding = legacyEnding;
|
|
351
375
|
exports.loadConfig = loadConfig;
|
|
352
376
|
exports.loadPkg = loadPkg;
|
|
353
377
|
exports.loadPkgWithReporting = loadPkgWithReporting;
|
|
354
378
|
exports.loadTSConfig = loadTSConfig;
|
|
355
379
|
exports.parseExports = parseExports;
|
|
380
|
+
exports.pkgExtMap = pkgExtMap;
|
|
356
381
|
exports.resolveBuildContext = resolveBuildContext;
|
|
357
382
|
exports.resolveConfigProperty = resolveConfigProperty;
|
|
358
383
|
//# sourceMappingURL=consoleSpy.cjs.map
|