@sanity/pkg-utils 7.4.1-canary.0 → 7.5.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/index.cjs +2022 -260
- package/dist/_chunks-cjs/index.cjs.map +1 -1
- package/dist/_chunks-es/build.js +106 -17
- package/dist/_chunks-es/build.js.map +1 -1
- package/dist/_chunks-es/check.js +125 -37
- package/dist/_chunks-es/check.js.map +1 -1
- package/dist/_chunks-es/consoleSpy.js +541 -0
- package/dist/_chunks-es/consoleSpy.js.map +1 -0
- package/dist/_chunks-es/index.js +774 -180
- package/dist/_chunks-es/index.js.map +1 -1
- package/dist/_chunks-es/init.js +493 -9
- package/dist/_chunks-es/init.js.map +1 -1
- package/dist/_chunks-es/{logger.js → isRecord.js} +15 -2
- package/dist/_chunks-es/isRecord.js.map +1 -0
- package/dist/_chunks-es/resolveRolldownConfig.js +1 -1
- package/dist/_chunks-es/spinner.js +16 -0
- package/dist/_chunks-es/spinner.js.map +1 -0
- package/dist/_chunks-es/watch.js +115 -9
- package/dist/_chunks-es/watch.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.d.cts +408 -487
- package/dist/index.d.ts +408 -487
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/_chunks-cjs/findConfigFile.cjs +0 -24
- package/dist/_chunks-cjs/findConfigFile.cjs.map +0 -1
- package/dist/_chunks-cjs/index2.cjs +0 -781
- package/dist/_chunks-cjs/index2.cjs.map +0 -1
- package/dist/_chunks-cjs/index3.cjs +0 -50
- package/dist/_chunks-cjs/index3.cjs.map +0 -1
- package/dist/_chunks-cjs/printPackageTree.cjs +0 -42
- package/dist/_chunks-cjs/printPackageTree.cjs.map +0 -1
- package/dist/_chunks-cjs/resolveBuildContext.cjs +0 -176
- package/dist/_chunks-cjs/resolveBuildContext.cjs.map +0 -1
- package/dist/_chunks-cjs/resolveBuildTasks.cjs +0 -111
- package/dist/_chunks-cjs/resolveBuildTasks.cjs.map +0 -1
- package/dist/_chunks-cjs/resolveConfigProperty.cjs +0 -6
- package/dist/_chunks-cjs/resolveConfigProperty.cjs.map +0 -1
- package/dist/_chunks-cjs/resolveWatchTasks.cjs +0 -79
- package/dist/_chunks-cjs/resolveWatchTasks.cjs.map +0 -1
- package/dist/_chunks-cjs/template.cjs +0 -446
- package/dist/_chunks-cjs/template.cjs.map +0 -1
- package/dist/_chunks-cjs/validatePkg.cjs +0 -71
- package/dist/_chunks-cjs/validatePkg.cjs.map +0 -1
- package/dist/_chunks-cjs/watchConfigFiles.cjs +0 -59
- package/dist/_chunks-cjs/watchConfigFiles.cjs.map +0 -1
- package/dist/_chunks-es/fileExists.js +0 -12
- package/dist/_chunks-es/fileExists.js.map +0 -1
- package/dist/_chunks-es/findConfigFile.js +0 -23
- package/dist/_chunks-es/findConfigFile.js.map +0 -1
- package/dist/_chunks-es/index2.js +0 -769
- package/dist/_chunks-es/index2.js.map +0 -1
- package/dist/_chunks-es/index3.js +0 -51
- package/dist/_chunks-es/index3.js.map +0 -1
- package/dist/_chunks-es/loadPkgWithReporting.js +0 -100
- package/dist/_chunks-es/loadPkgWithReporting.js.map +0 -1
- package/dist/_chunks-es/logger.js.map +0 -1
- package/dist/_chunks-es/printPackageTree.js +0 -44
- package/dist/_chunks-es/printPackageTree.js.map +0 -1
- package/dist/_chunks-es/resolveBuildContext.js +0 -177
- package/dist/_chunks-es/resolveBuildContext.js.map +0 -1
- package/dist/_chunks-es/resolveBuildTasks.js +0 -109
- package/dist/_chunks-es/resolveBuildTasks.js.map +0 -1
- package/dist/_chunks-es/resolveConfigProperty.js +0 -7
- package/dist/_chunks-es/resolveConfigProperty.js.map +0 -1
- package/dist/_chunks-es/resolveWatchTasks.js +0 -77
- package/dist/_chunks-es/resolveWatchTasks.js.map +0 -1
- package/dist/_chunks-es/template.js +0 -449
- package/dist/_chunks-es/template.js.map +0 -1
- package/dist/_chunks-es/validatePkg.js +0 -72
- package/dist/_chunks-es/validatePkg.js.map +0 -1
- package/dist/_chunks-es/watchConfigFiles.js +0 -45
- package/dist/_chunks-es/watchConfigFiles.js.map +0 -1
package/dist/_chunks-es/index.js
CHANGED
|
@@ -1,182 +1,193 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import "
|
|
3
|
-
import "
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import "
|
|
8
|
-
import "
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import "
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { Observable, from } from "rxjs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import * as rimraf from "rimraf";
|
|
5
|
+
import { rimraf as rimraf$1 } from "rimraf";
|
|
6
|
+
import ts from "typescript";
|
|
7
|
+
import fs, { readFile } from "node:fs/promises";
|
|
8
|
+
import { ExtractorConfig, Extractor } from "@microsoft/api-extractor";
|
|
9
|
+
import { mkdirp } from "mkdirp";
|
|
10
|
+
import * as prettier from "prettier";
|
|
11
|
+
import { createRequire } from "node:module";
|
|
12
|
+
import { TSDocConfigFile } from "@microsoft/tsdoc-config";
|
|
13
|
+
import { parse } from "jsonc-parser";
|
|
14
|
+
import { parse as parse$1, print } from "recast";
|
|
15
|
+
import typeScriptParser from "recast/parsers/typescript.js";
|
|
16
|
+
import { createConsoleSpy, resolveConfigProperty, pkgExtMap } from "./consoleSpy.js";
|
|
17
|
+
import { rollup, watch } from "rollup";
|
|
18
|
+
import { optimizeLodashImports } from "@optimize-lodash/rollup-plugin";
|
|
19
|
+
import alias from "@rollup/plugin-alias";
|
|
20
|
+
import { babel, getBabelOutputPlugin } from "@rollup/plugin-babel";
|
|
21
|
+
import commonjs from "@rollup/plugin-commonjs";
|
|
22
|
+
import json from "@rollup/plugin-json";
|
|
23
|
+
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
24
|
+
import replace from "@rollup/plugin-replace";
|
|
25
|
+
import terser from "@rollup/plugin-terser";
|
|
26
|
+
import esbuild from "rollup-plugin-esbuild";
|
|
27
|
+
function printExtractMessages(ctx, messages) {
|
|
28
|
+
const { cwd, logger } = ctx, warnings = messages.filter((msg) => msg.logLevel === "warning");
|
|
29
|
+
warnings.length && logger.log();
|
|
30
|
+
for (const msg of warnings) {
|
|
31
|
+
const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath);
|
|
32
|
+
msg.messageId !== "TS6307" && logger.log(
|
|
33
|
+
[
|
|
34
|
+
`${chalk.cyan(sourceFilePath || "?")}`,
|
|
35
|
+
`:${chalk.yellow(msg.sourceFileLine)}:${chalk.yellow(msg.sourceFileColumn)}`,
|
|
36
|
+
` - ${chalk.yellow("warning")} ${chalk.gray(msg.messageId)}
|
|
37
|
+
`,
|
|
38
|
+
msg.text,
|
|
39
|
+
`
|
|
40
|
+
`
|
|
41
|
+
].join("")
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
const errors = messages.filter((msg) => msg.logLevel === "error");
|
|
45
|
+
!warnings.length && errors.length && logger.log("");
|
|
46
|
+
for (const msg of errors) {
|
|
47
|
+
const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath);
|
|
48
|
+
logger.log(
|
|
49
|
+
[
|
|
50
|
+
`${chalk.cyan(sourceFilePath || "?")}`,
|
|
51
|
+
`:${chalk.yellow(msg.sourceFileLine)}:${chalk.yellow(msg.sourceFileColumn)}`,
|
|
52
|
+
` - ${chalk.red("error")} ${chalk.gray(msg.messageId)}
|
|
53
|
+
`,
|
|
54
|
+
msg.text,
|
|
55
|
+
`
|
|
56
|
+
`
|
|
57
|
+
].join("")
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
errors.length && process.exit(1);
|
|
30
61
|
}
|
|
31
|
-
|
|
32
|
-
|
|
62
|
+
var printExtractMessages$1 = /* @__PURE__ */ Object.freeze({
|
|
63
|
+
__proto__: null,
|
|
64
|
+
printExtractMessages
|
|
65
|
+
});
|
|
66
|
+
function printDiagnostic(options) {
|
|
67
|
+
const { cwd, logger, diagnostic } = options;
|
|
68
|
+
if (diagnostic.file && diagnostic.start) {
|
|
69
|
+
const { line, character } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start), message = ts.flattenDiagnosticMessageText(diagnostic.messageText, `
|
|
70
|
+
`), file = path.relative(cwd, diagnostic.file.fileName), output = [
|
|
71
|
+
`${chalk.yellow(file)}:${chalk.blue(line + 1)}:${chalk.blue(character + 1)} - `,
|
|
72
|
+
`${chalk.gray(`TS${diagnostic.code}:`)} ${message}`
|
|
73
|
+
].join("");
|
|
74
|
+
diagnostic.category === ts.DiagnosticCategory.Error && logger.error(output), diagnostic.category === ts.DiagnosticCategory.Warning && logger.warn(output), diagnostic.category === ts.DiagnosticCategory.Message && logger.log(output), diagnostic.category === ts.DiagnosticCategory.Suggestion && logger.log(output);
|
|
75
|
+
} else
|
|
76
|
+
logger.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, `
|
|
77
|
+
`));
|
|
33
78
|
}
|
|
34
|
-
function
|
|
35
|
-
|
|
79
|
+
async function buildTypes(options) {
|
|
80
|
+
const { cwd, logger, outDir, tsconfig, strict = !1 } = options, compilerOptions = {
|
|
81
|
+
...tsconfig.options,
|
|
82
|
+
declaration: !0,
|
|
83
|
+
declarationDir: outDir,
|
|
84
|
+
emitDeclarationOnly: !0,
|
|
85
|
+
noEmit: !1,
|
|
86
|
+
noEmitOnError: strict ? !0 : tsconfig.options.noEmitOnError ?? !0,
|
|
87
|
+
outDir
|
|
88
|
+
}, program = ts.createProgram(tsconfig.fileNames, compilerOptions), emitResult = program.emit(), allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
89
|
+
for (const diagnostic of allDiagnostics)
|
|
90
|
+
printDiagnostic({ cwd, logger, diagnostic });
|
|
91
|
+
if (emitResult.emitSkipped && allDiagnostics.filter((diag) => diag.category === ts.DiagnosticCategory.Error).length)
|
|
92
|
+
throw new Error("failed to compile TypeScript definitions");
|
|
36
93
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
esm: mjsEnding
|
|
42
|
-
},
|
|
43
|
-
// pkg.type: "module"
|
|
44
|
-
module: {
|
|
45
|
-
commonjs: cjsEnding,
|
|
46
|
-
esm: defaultEnding
|
|
94
|
+
class DtsError extends Error {
|
|
95
|
+
messages;
|
|
96
|
+
constructor(message, messages) {
|
|
97
|
+
super(message), this.messages = messages;
|
|
47
98
|
}
|
|
48
|
-
};
|
|
49
|
-
function validateExports(_exports, options) {
|
|
50
|
-
const { pkg } = options, type = pkg.type || "commonjs", ext = pkgExtMap[type], errors = [];
|
|
51
|
-
for (const exp of _exports)
|
|
52
|
-
exp.require && !exp.require.endsWith(ext.commonjs) && errors.push(
|
|
53
|
-
`package.json with \`type: "${type}"\` - \`exports["${exp._path}"].require\` must end with "${ext.commonjs}"`
|
|
54
|
-
), exp.import && !exp.import.endsWith(ext.esm) && errors.push(
|
|
55
|
-
`package.json with \`type: "${type}"\` - \`exports["${exp._path}"].import\` must end with "${ext.esm}"`
|
|
56
|
-
);
|
|
57
|
-
return errors;
|
|
58
99
|
}
|
|
59
|
-
function
|
|
60
|
-
const {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
" }"
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
errors.push(
|
|
89
|
-
...[
|
|
90
|
-
"package.json: `exports` are missing, it should be:",
|
|
91
|
-
'"exports": {',
|
|
92
|
-
' ".": {',
|
|
93
|
-
` "source": ${JSON.stringify(pkg.source)},`,
|
|
94
|
-
// If browser conditions are detected then add them to the suggestion
|
|
95
|
-
...maybeBrowserCondition.length > 0 ? maybeBrowserCondition : [],
|
|
96
|
-
type === "commonjs" && ` "import": ${JSON.stringify(importExport)},`,
|
|
97
|
-
type === "module" && ` "require": ${JSON.stringify(requireExport)},`,
|
|
98
|
-
` "default": ${JSON.stringify(defaultExport)}`,
|
|
99
|
-
" },",
|
|
100
|
-
' "./package.json": "./package.json"',
|
|
101
|
-
"}"
|
|
102
|
-
].filter(Boolean)
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (errors.length)
|
|
107
|
-
throw new Error(`
|
|
108
|
-
- ` + errors.join(`
|
|
109
|
-
- `));
|
|
110
|
-
if (!pkg.exports)
|
|
111
|
-
throw new Error(
|
|
112
|
-
`
|
|
113
|
-
- ` + [
|
|
114
|
-
"package.json: `exports` are missing, please set a minimal configuration, for example:",
|
|
115
|
-
'"exports": {',
|
|
116
|
-
' ".": {',
|
|
117
|
-
' "source": "./src/index.js",',
|
|
118
|
-
' "default": "./dist/index.js"',
|
|
119
|
-
" },",
|
|
120
|
-
' "./package.json": "./package.json"',
|
|
121
|
-
"}"
|
|
122
|
-
].join(`
|
|
123
|
-
- `)
|
|
124
|
-
);
|
|
125
|
-
const _exports = [];
|
|
126
|
-
strict && strictOptions2.noPackageJsonTypings !== "off" && "typings" in pkg && report(strictOptions2.noPackageJsonTypings, "package.json: `typings` should be `types`"), strict && strictOptions2.alwaysPackageJsonTypes !== "off" && !pkg.types && typeof pkg.exports?.["."] == "object" && "source" in pkg.exports["."] && pkg.exports["."].source?.endsWith(".ts") && report(
|
|
127
|
-
strictOptions2.alwaysPackageJsonTypes,
|
|
128
|
-
"package.json: `types` must be declared for the npm listing to show as a TypeScript module."
|
|
129
|
-
), strict && !pkg.exports["./package.json"] && errors.push('package.json: `exports["./package.json"] must be declared.');
|
|
130
|
-
for (const [exportPath, exportEntry] of Object.entries(pkg.exports))
|
|
131
|
-
if (exportPath.endsWith(".json") || typeof exportEntry == "string" && exportEntry.endsWith(".json"))
|
|
132
|
-
exportPath === "./package.json" && exportEntry !== "./package.json" && errors.push('package.json: `exports["./package.json"]` must be "./package.json".');
|
|
133
|
-
else if (exportPath.endsWith(".css"))
|
|
134
|
-
typeof exportEntry == "string" && !existsSync(resolve(cwd, exportEntry)) ? errors.push(
|
|
135
|
-
`package.json: \`exports[${JSON.stringify(exportPath)}]\`: file does not exist.`
|
|
136
|
-
) : typeof exportEntry != "string" && errors.push(
|
|
137
|
-
`package.json: \`exports[${JSON.stringify(exportPath)}]\`: export conditions not supported for CSS files.`
|
|
138
|
-
);
|
|
139
|
-
else if (!(isRecord(exportEntry) && "svelte" in exportEntry))
|
|
140
|
-
if (isPkgExport(exportEntry)) {
|
|
141
|
-
const exp = {
|
|
142
|
-
_exported: !0,
|
|
143
|
-
_path: exportPath,
|
|
144
|
-
...exportEntry
|
|
145
|
-
};
|
|
146
|
-
if (!exp.default) {
|
|
147
|
-
const fallback = type === "module" ? exp.import : exp.require;
|
|
148
|
-
fallback && (exp.default = fallback);
|
|
100
|
+
function createApiExtractorConfig(options) {
|
|
101
|
+
const {
|
|
102
|
+
bundledPackages,
|
|
103
|
+
distPath,
|
|
104
|
+
exportPath,
|
|
105
|
+
filePath,
|
|
106
|
+
messages,
|
|
107
|
+
projectFolder,
|
|
108
|
+
mainEntryPointFilePath,
|
|
109
|
+
tsconfig,
|
|
110
|
+
tsconfigPath,
|
|
111
|
+
dtsRollupEnabled
|
|
112
|
+
} = options;
|
|
113
|
+
return {
|
|
114
|
+
apiReport: {
|
|
115
|
+
enabled: !1,
|
|
116
|
+
reportFileName: "<unscopedPackageName>.api.md"
|
|
117
|
+
},
|
|
118
|
+
bundledPackages,
|
|
119
|
+
// If `paths` are used for self-referencing imports (e.g. the module is named `sanity`, and the `sanity/structure` export is also importing from `sanity/router`),
|
|
120
|
+
compiler: tsconfig.options.paths ? {
|
|
121
|
+
overrideTsconfig: {
|
|
122
|
+
extends: tsconfigPath,
|
|
123
|
+
compilerOptions: {
|
|
124
|
+
// An empty object replaces whatever is in the original tsconfig file
|
|
125
|
+
paths: {}
|
|
149
126
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
127
|
+
}
|
|
128
|
+
} : { tsconfigFilePath: tsconfigPath },
|
|
129
|
+
docModel: {
|
|
130
|
+
enabled: !1,
|
|
131
|
+
apiJsonFilePath: path.resolve(distPath, `${exportPath}.api.json`)
|
|
132
|
+
},
|
|
133
|
+
dtsRollup: {
|
|
134
|
+
enabled: dtsRollupEnabled,
|
|
135
|
+
untrimmedFilePath: path.resolve(distPath, filePath)
|
|
136
|
+
// betaTrimmedFilePath: path.resolve(distPath, filePath.replace('.d.ts', '-beta.d.ts')),
|
|
137
|
+
// publicTrimmedFilePath: path.resolve(distPath, filePath.replace('.d.ts', '-public.d.ts')),
|
|
138
|
+
},
|
|
139
|
+
tsdocMetadata: {
|
|
140
|
+
enabled: !1
|
|
141
|
+
},
|
|
142
|
+
messages,
|
|
143
|
+
mainEntryPointFilePath,
|
|
144
|
+
projectFolder
|
|
145
|
+
};
|
|
164
146
|
}
|
|
165
|
-
|
|
166
|
-
|
|
147
|
+
var createApiExtractorConfig$1 = /* @__PURE__ */ Object.freeze({
|
|
148
|
+
__proto__: null,
|
|
149
|
+
createApiExtractorConfig
|
|
150
|
+
});
|
|
151
|
+
const require2 = createRequire(import.meta.url);
|
|
152
|
+
async function createTSDocConfig(opts) {
|
|
153
|
+
const { customTags } = opts;
|
|
154
|
+
if (customTags.length === 0)
|
|
155
|
+
return;
|
|
156
|
+
const tsDocBaseBuf = await readFile(
|
|
157
|
+
require2.resolve("@microsoft/api-extractor/extends/tsdoc-base.json")
|
|
158
|
+
), tsDocBaseConfig = parse(tsDocBaseBuf.toString()), tagDefinitions = (tsDocBaseConfig.tagDefinitions || []).concat(
|
|
159
|
+
customTags.map((t) => ({
|
|
160
|
+
tagName: `@${t.name}`,
|
|
161
|
+
syntaxKind: t.syntaxKind,
|
|
162
|
+
allowMultiple: t.allowMultiple
|
|
163
|
+
}))
|
|
164
|
+
), supportForTags = { ...tsDocBaseConfig.supportForTags };
|
|
165
|
+
for (const customTag of customTags)
|
|
166
|
+
supportForTags[`@${customTag.name}`] = !0;
|
|
167
|
+
return TSDocConfigFile.loadFromObject({
|
|
168
|
+
...tsDocBaseConfig,
|
|
169
|
+
noStandardTags: !1,
|
|
170
|
+
tagDefinitions,
|
|
171
|
+
supportForTags
|
|
172
|
+
});
|
|
167
173
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
noImplicitBrowsersList: toggle.default("warn"),
|
|
172
|
-
alwaysPackageJsonTypes: toggle.default("error"),
|
|
173
|
-
alwaysPackageJsonMain: toggle.default("error"),
|
|
174
|
-
alwaysPackageJsonFiles: toggle.default("error")
|
|
175
|
-
}).strict(), validationSchema = z.object({
|
|
176
|
-
strictOptions: strictOptions.default({})
|
|
174
|
+
var createTSDocConfig$1 = /* @__PURE__ */ Object.freeze({
|
|
175
|
+
__proto__: null,
|
|
176
|
+
createTSDocConfig
|
|
177
177
|
});
|
|
178
|
-
function
|
|
179
|
-
|
|
178
|
+
async function extractModuleBlocksFromTypes({
|
|
179
|
+
tsOutDir,
|
|
180
|
+
extractResult
|
|
181
|
+
}) {
|
|
182
|
+
const program = extractResult.compilerState.program, moduleBlocks = [], sourceFiles = [...program.getSourceFiles()].filter((sourceFile) => sourceFile.fileName.includes(tsOutDir));
|
|
183
|
+
for (const sourceFile of sourceFiles)
|
|
184
|
+
sourceFile.text.includes("declare module") && moduleBlocks.push(...extractModuleBlocks(sourceFile.text));
|
|
185
|
+
return moduleBlocks;
|
|
186
|
+
}
|
|
187
|
+
function extractModuleBlocks(fileContent) {
|
|
188
|
+
return parse$1(fileContent, {
|
|
189
|
+
parser: typeScriptParser
|
|
190
|
+
}).program.body.filter((node) => node.type === "TSModuleDeclaration").map((node) => print(node).code);
|
|
180
191
|
}
|
|
181
192
|
const LOG_LEVELS = {
|
|
182
193
|
error: "error",
|
|
@@ -259,17 +270,600 @@ function getExtractMessagesConfig(options) {
|
|
|
259
270
|
}
|
|
260
271
|
};
|
|
261
272
|
}
|
|
273
|
+
var getExtractMessagesConfig$1 = /* @__PURE__ */ Object.freeze({
|
|
274
|
+
__proto__: null,
|
|
275
|
+
getExtractMessagesConfig
|
|
276
|
+
});
|
|
277
|
+
async function extractTypes(options) {
|
|
278
|
+
const {
|
|
279
|
+
bundledPackages,
|
|
280
|
+
customTags,
|
|
281
|
+
distPath,
|
|
282
|
+
exportPath,
|
|
283
|
+
files,
|
|
284
|
+
filePaths,
|
|
285
|
+
projectPath,
|
|
286
|
+
rules,
|
|
287
|
+
sourceTypesPath,
|
|
288
|
+
tmpPath,
|
|
289
|
+
tsconfig,
|
|
290
|
+
tsconfigPath,
|
|
291
|
+
extractorDisabled
|
|
292
|
+
} = options, tsdocConfigFile = await createTSDocConfig({
|
|
293
|
+
customTags: customTags || []
|
|
294
|
+
}), filePath = filePaths[0].replace(/\.d\.[mc]ts$/, ".d.ts"), shouldCleanUpDts = !filePaths.includes(filePath), extractorConfig = ExtractorConfig.prepare({
|
|
295
|
+
configObject: createApiExtractorConfig({
|
|
296
|
+
bundledPackages,
|
|
297
|
+
distPath,
|
|
298
|
+
exportPath,
|
|
299
|
+
filePath,
|
|
300
|
+
messages: getExtractMessagesConfig({ rules, disabled: extractorDisabled }),
|
|
301
|
+
projectFolder: projectPath,
|
|
302
|
+
mainEntryPointFilePath: sourceTypesPath,
|
|
303
|
+
tsconfig,
|
|
304
|
+
tsconfigPath,
|
|
305
|
+
dtsRollupEnabled: !0
|
|
306
|
+
}),
|
|
307
|
+
configObjectFullPath: void 0,
|
|
308
|
+
tsdocConfigFile,
|
|
309
|
+
packageJsonFullPath: path.resolve(projectPath, "package.json")
|
|
310
|
+
}), messages = [], extractorResult = Extractor.invoke(extractorConfig, {
|
|
311
|
+
// Equivalent to the "--local" command-line parameter
|
|
312
|
+
localBuild: !0,
|
|
313
|
+
// Equivalent to the "--verbose" command-line parameter
|
|
314
|
+
showVerboseMessages: !0,
|
|
315
|
+
// handle messages
|
|
316
|
+
messageCallback(message) {
|
|
317
|
+
messages.push(message), message.handled = !0;
|
|
318
|
+
}
|
|
319
|
+
}), typesPath = path.resolve(distPath, filePath), typesBuf = await fs.readFile(typesPath), prettierConfig = await prettier.resolveConfig(typesPath);
|
|
320
|
+
await mkdirp(path.dirname(typesPath));
|
|
321
|
+
const moduleBlocks = await extractModuleBlocksFromTypes({
|
|
322
|
+
extractResult: extractorResult,
|
|
323
|
+
tsOutDir: tmpPath
|
|
324
|
+
}), code = [typesBuf.toString(), ...moduleBlocks].join(`
|
|
325
|
+
|
|
326
|
+
`), prettyCode = await prettier.format(code, {
|
|
327
|
+
...prettierConfig,
|
|
328
|
+
filepath: typesPath
|
|
329
|
+
});
|
|
330
|
+
for (const expFilePath of filePaths) {
|
|
331
|
+
const expTypesPath = path.resolve(distPath, expFilePath);
|
|
332
|
+
await fs.writeFile(expTypesPath, prettyCode), files.push({
|
|
333
|
+
type: "types",
|
|
334
|
+
path: expTypesPath
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
return shouldCleanUpDts && await fs.unlink(typesPath), { extractorResult, messages };
|
|
338
|
+
}
|
|
339
|
+
async function doExtract(ctx, task) {
|
|
340
|
+
const { config, cwd, files, logger, strict, ts: ts2, bundledPackages } = ctx;
|
|
341
|
+
if (!ts2.config || !ts2.configPath)
|
|
342
|
+
return { type: "dts", messages: [], results: [] };
|
|
343
|
+
const { outDir, rootDir = cwd } = ts2.config.options;
|
|
344
|
+
if (!outDir)
|
|
345
|
+
throw new Error("tsconfig.json is missing `compilerOptions.outDir`");
|
|
346
|
+
const tmpPath = path.resolve(outDir, "__tmp__");
|
|
347
|
+
await buildTypes({ cwd, logger, outDir: tmpPath, strict, tsconfig: ts2.config });
|
|
348
|
+
const messages = [], results = [];
|
|
349
|
+
for (const entry of task.entries) {
|
|
350
|
+
const exportPath = entry.exportPath === "." ? "./index" : entry.exportPath, sourceTypesPath = path.resolve(
|
|
351
|
+
tmpPath,
|
|
352
|
+
path.relative(rootDir, path.resolve(cwd, entry.sourcePath)).replace(/\.ts$/, ".d.ts")
|
|
353
|
+
), targetPaths = entry.targetPaths.map((targetPath) => path.resolve(cwd, targetPath)), filePaths = targetPaths.map((targetPath) => path.relative(outDir, targetPath)), result = await extractTypes({
|
|
354
|
+
bundledPackages: bundledPackages || [],
|
|
355
|
+
customTags: config?.extract?.customTags,
|
|
356
|
+
distPath: outDir,
|
|
357
|
+
exportPath,
|
|
358
|
+
files,
|
|
359
|
+
filePaths,
|
|
360
|
+
projectPath: cwd,
|
|
361
|
+
rules: config?.extract?.rules,
|
|
362
|
+
sourceTypesPath,
|
|
363
|
+
tsconfig: ts2.config,
|
|
364
|
+
tmpPath,
|
|
365
|
+
tsconfigPath: path.resolve(cwd, ts2.configPath || "tsconfig.json"),
|
|
366
|
+
extractorDisabled: config?.extract?.enabled === !1
|
|
367
|
+
});
|
|
368
|
+
messages.push(...result.messages);
|
|
369
|
+
const errors = result.messages.filter((msg) => msg.logLevel === "error");
|
|
370
|
+
if (errors.length > 0)
|
|
371
|
+
throw await rimraf$1(tmpPath), new DtsError(`encountered ${errors.length} errors when extracting types`, errors);
|
|
372
|
+
results.push({ sourcePath: path.resolve(cwd, entry.sourcePath), filePaths: targetPaths });
|
|
373
|
+
}
|
|
374
|
+
return await rimraf$1(tmpPath), { type: "dts", messages, results };
|
|
375
|
+
}
|
|
376
|
+
const dtsTask = {
|
|
377
|
+
name: (ctx, task) => [
|
|
378
|
+
`Build type definitions with ${chalk.bold(ctx.dts)}...`,
|
|
379
|
+
" entries:",
|
|
380
|
+
...task.entries.map((entry) => entry.targetPaths.map((targetPath) => [
|
|
381
|
+
` - ${chalk.cyan(entry.importId)}: `,
|
|
382
|
+
`${chalk.yellow(entry.sourcePath)} ${chalk.gray("\u2192")} ${chalk.yellow(targetPath)}`
|
|
383
|
+
].join("")).join(`
|
|
384
|
+
`))
|
|
385
|
+
].join(`
|
|
386
|
+
`),
|
|
387
|
+
exec: (ctx, task) => new Observable((observer) => {
|
|
388
|
+
doExtract(ctx, task).then((result) => {
|
|
389
|
+
observer.next(result), observer.complete();
|
|
390
|
+
}).catch((err) => {
|
|
391
|
+
observer.error(err);
|
|
392
|
+
});
|
|
393
|
+
}),
|
|
394
|
+
complete: (ctx, _task, result) => {
|
|
395
|
+
printExtractMessages(ctx, result.messages);
|
|
396
|
+
},
|
|
397
|
+
error: (ctx, _task, err) => {
|
|
398
|
+
const { logger } = ctx;
|
|
399
|
+
err instanceof DtsError ? printExtractMessages(ctx, err.messages) : err instanceof Error && logger.error(err);
|
|
400
|
+
}
|
|
401
|
+
}, dtsWatchTask = {
|
|
402
|
+
name: (_ctx, task) => [
|
|
403
|
+
"build type definitions",
|
|
404
|
+
...task.entries.map((entry) => entry.targetPaths.map((targetPath) => [
|
|
405
|
+
` - ${chalk.cyan(entry.importId)}: `,
|
|
406
|
+
`${chalk.yellow(entry.sourcePath)} ${chalk.gray("\u2192")} ${chalk.yellow(targetPath)}`
|
|
407
|
+
].join("")))
|
|
408
|
+
].join(`
|
|
409
|
+
`),
|
|
410
|
+
exec: (ctx, task) => {
|
|
411
|
+
const { config, cwd, files, logger, strict, ts: tsContext, bundledPackages } = ctx;
|
|
412
|
+
return new Observable((observer) => {
|
|
413
|
+
if (!tsContext.config || !tsContext.configPath) {
|
|
414
|
+
observer.next({ type: "dts", messages: [], results: [] }), observer.complete();
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
const { outDir, rootDir = cwd } = tsContext.config.options;
|
|
418
|
+
if (!outDir) {
|
|
419
|
+
observer.error(new Error("tsconfig.json is missing `compilerOptions.outDir`"));
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
const tmpPath = path.resolve(outDir, "__tmp__");
|
|
423
|
+
buildTypes({
|
|
424
|
+
cwd,
|
|
425
|
+
logger,
|
|
426
|
+
outDir: tmpPath,
|
|
427
|
+
tsconfig: tsContext.config,
|
|
428
|
+
strict
|
|
429
|
+
}).catch((err) => {
|
|
430
|
+
observer.error(err);
|
|
431
|
+
});
|
|
432
|
+
const host = ts.createWatchCompilerHost(
|
|
433
|
+
tsContext.configPath,
|
|
434
|
+
{
|
|
435
|
+
...tsContext.config.options,
|
|
436
|
+
declaration: !0,
|
|
437
|
+
declarationDir: tmpPath,
|
|
438
|
+
emitDeclarationOnly: !0,
|
|
439
|
+
noEmit: !1,
|
|
440
|
+
noEmitOnError: strict ? !0 : tsContext.config.options.noEmitOnError ?? !0,
|
|
441
|
+
outDir: tmpPath
|
|
442
|
+
},
|
|
443
|
+
ts.sys,
|
|
444
|
+
ts.createEmitAndSemanticDiagnosticsBuilderProgram,
|
|
445
|
+
(diagnostic) => {
|
|
446
|
+
logger.error(ts.flattenDiagnosticMessageText(diagnostic.messageText, `
|
|
447
|
+
`));
|
|
448
|
+
},
|
|
449
|
+
(diagnostic) => {
|
|
450
|
+
logger.info(ts.flattenDiagnosticMessageText(diagnostic.messageText, `
|
|
451
|
+
`));
|
|
452
|
+
}
|
|
453
|
+
), origPostProgramCreate = host.afterProgramCreate;
|
|
454
|
+
host.afterProgramCreate = async (program) => {
|
|
455
|
+
origPostProgramCreate?.(program);
|
|
456
|
+
const messages = [], results = [];
|
|
457
|
+
for (const entry of task.entries) {
|
|
458
|
+
const exportPath = entry.exportPath === "." ? "./index" : entry.exportPath, sourceTypesPath = path.resolve(
|
|
459
|
+
tmpPath,
|
|
460
|
+
path.relative(rootDir, path.resolve(cwd, entry.sourcePath)).replace(/\.ts$/, ".d.ts")
|
|
461
|
+
), targetPaths = entry.targetPaths.map((targetPath) => path.resolve(cwd, targetPath)), filePaths = targetPaths.map((targetPath) => path.relative(outDir, targetPath));
|
|
462
|
+
try {
|
|
463
|
+
const result = await extractTypes({
|
|
464
|
+
bundledPackages: bundledPackages || [],
|
|
465
|
+
customTags: config?.extract?.customTags,
|
|
466
|
+
cwd,
|
|
467
|
+
distPath: outDir,
|
|
468
|
+
exportPath,
|
|
469
|
+
files,
|
|
470
|
+
filePaths,
|
|
471
|
+
projectPath: cwd,
|
|
472
|
+
rules: config?.extract?.rules,
|
|
473
|
+
sourceTypesPath,
|
|
474
|
+
tsconfig: tsContext.config,
|
|
475
|
+
tmpPath,
|
|
476
|
+
tsconfigPath: path.resolve(cwd, tsContext.configPath || "tsconfig.json"),
|
|
477
|
+
extractorDisabled: config?.extract?.enabled === !1
|
|
478
|
+
});
|
|
479
|
+
messages.push(...result.messages), results.push({ sourcePath: path.resolve(cwd, entry.sourcePath), filePaths: targetPaths });
|
|
480
|
+
} catch (err) {
|
|
481
|
+
if (err instanceof DtsError)
|
|
482
|
+
messages.push(...err.messages);
|
|
483
|
+
else {
|
|
484
|
+
observer.error(err);
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
observer.next({ type: "dts", messages, results });
|
|
490
|
+
};
|
|
491
|
+
const watchProgram = ts.createWatchProgram(host);
|
|
492
|
+
return () => {
|
|
493
|
+
watchProgram.close(), rimraf.sync(tmpPath);
|
|
494
|
+
};
|
|
495
|
+
});
|
|
496
|
+
},
|
|
497
|
+
complete: (ctx, task, result) => {
|
|
498
|
+
const { logger } = ctx;
|
|
499
|
+
printExtractMessages(ctx, result.messages), logger.success(
|
|
500
|
+
`build type definitions
|
|
501
|
+
${task.entries.map(
|
|
502
|
+
(entry) => ` - ${chalk.cyan(entry.importId)}: ${chalk.yellow(entry.sourcePath)} ${chalk.gray("\u2192")} ${chalk.yellow(entry.targetPaths.join(", "))}`
|
|
503
|
+
).join(`
|
|
504
|
+
`)}`
|
|
505
|
+
), logger.log("");
|
|
506
|
+
},
|
|
507
|
+
error: (ctx, _task, err) => {
|
|
508
|
+
const { logger } = ctx;
|
|
509
|
+
err instanceof DtsError ? printExtractMessages(ctx, err.messages) : err instanceof Error && logger.error(err);
|
|
510
|
+
}
|
|
511
|
+
}, rolldownDtsTask = {
|
|
512
|
+
name: (ctx, task) => {
|
|
513
|
+
const bundleEntries = task.entries.filter((e) => e.path.includes("__$$bundle_")), entries = task.entries.filter((e) => !e.path.includes("__$$bundle_")), targetLines = task.target.length ? [" target:", ...task.target.map((t) => ` - ${chalk.yellow(t)}`)] : [], bundlesLines = bundleEntries.length ? [
|
|
514
|
+
" bundles:",
|
|
515
|
+
...bundleEntries.map(
|
|
516
|
+
(e) => [
|
|
517
|
+
" - ",
|
|
518
|
+
`${chalk.yellow(e.source)} ${chalk.gray("\u2192")} ${chalk.yellow(replaceFileEnding(e.output))}`
|
|
519
|
+
].join("")
|
|
520
|
+
)
|
|
521
|
+
] : [], entriesLines = entries.length ? [
|
|
522
|
+
" entries:",
|
|
523
|
+
...entries.map(
|
|
524
|
+
(e) => [
|
|
525
|
+
" - ",
|
|
526
|
+
`${chalk.cyan(path.join(ctx.pkg.name, e.path))}: `,
|
|
527
|
+
`${chalk.yellow(e.source)} ${chalk.gray("\u2192")} ${chalk.yellow(replaceFileEnding(e.output))}`
|
|
528
|
+
].join("")
|
|
529
|
+
)
|
|
530
|
+
] : [];
|
|
531
|
+
return [
|
|
532
|
+
`Build type definitions with ${chalk.bold("rolldown")}...`,
|
|
533
|
+
` format: ${chalk.yellow(task.format)}`,
|
|
534
|
+
...targetLines,
|
|
535
|
+
...bundlesLines,
|
|
536
|
+
...entriesLines
|
|
537
|
+
].join(`
|
|
538
|
+
`);
|
|
539
|
+
},
|
|
540
|
+
exec: (ctx, task) => from(execPromise$1(ctx, task)),
|
|
541
|
+
complete: () => {
|
|
542
|
+
},
|
|
543
|
+
error: (_ctx, _task, err) => {
|
|
544
|
+
console.error(err);
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
async function execPromise$1(ctx, task) {
|
|
548
|
+
const [{ rolldown }, { resolveRolldownConfig }] = await Promise.all([
|
|
549
|
+
import("rolldown"),
|
|
550
|
+
import("./resolveRolldownConfig.js")
|
|
551
|
+
]), { distPath, files, logger } = ctx, outDir = path.relative(ctx.cwd, distPath), consoleSpy = createConsoleSpy({
|
|
552
|
+
onRestored: (messages) => {
|
|
553
|
+
for (const msg of messages) {
|
|
554
|
+
const text = String(msg.args[0]);
|
|
555
|
+
msg.code !== "CIRCULAR_DEPENDENCY" && (text.startsWith("Dynamic import can only") || text.startsWith("Sourcemap is likely to be incorrect") || (msg.type === "log" && logger.info(...msg.args), msg.type === "warn" && logger.warn(...msg.args), msg.type === "error" && logger.error(...msg.args)));
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
try {
|
|
560
|
+
const { inputOptions, outputOptions } = resolveRolldownConfig(ctx, task), bundle = await rolldown({
|
|
561
|
+
...inputOptions,
|
|
562
|
+
onwarn(warning) {
|
|
563
|
+
consoleSpy.messages.push({
|
|
564
|
+
type: "warn",
|
|
565
|
+
code: warning.code,
|
|
566
|
+
args: [warning.message]
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
}), { output } = await bundle.generate(outputOptions);
|
|
570
|
+
for (const chunkOrAsset of output)
|
|
571
|
+
chunkOrAsset.type === "asset" ? files.push({
|
|
572
|
+
type: "asset",
|
|
573
|
+
path: path.resolve(outDir, chunkOrAsset.fileName)
|
|
574
|
+
}) : files.push({
|
|
575
|
+
type: "chunk",
|
|
576
|
+
path: path.resolve(outDir, chunkOrAsset.fileName)
|
|
577
|
+
});
|
|
578
|
+
await bundle.write(outputOptions), await bundle.close(), consoleSpy.restore();
|
|
579
|
+
} catch (err) {
|
|
580
|
+
throw consoleSpy.restore(), err;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
function replaceFileEnding(path2) {
|
|
584
|
+
switch (!0) {
|
|
585
|
+
case path2.endsWith(".mjs"):
|
|
586
|
+
return path2.replace(/\.mjs$/, ".d.mts");
|
|
587
|
+
case path2.endsWith(".cjs"):
|
|
588
|
+
return path2.replace(/\.cjs$/, ".d.cts");
|
|
589
|
+
default:
|
|
590
|
+
return path2.replace(/\.js$/, ".d.ts");
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
function resolveRollupConfig(ctx, buildTask) {
|
|
594
|
+
const { format, runtime, target } = buildTask, { config, cwd, exports: _exports, external, distPath, logger, pkg, ts: ts2 } = ctx, outputExt = pkgExtMap[pkg.type || "commonjs"][format], minify = config?.minify ?? !1, outDir = path.relative(cwd, distPath), pathAliases = Object.fromEntries(
|
|
595
|
+
Object.entries(ts2.config?.options.paths || {}).map(([key, val]) => [key, path.resolve(cwd, ts2.config?.options.baseUrl || ".", val[0])])
|
|
596
|
+
), entries = buildTask.entries.map((entry) => ({
|
|
597
|
+
...entry,
|
|
598
|
+
name: path.relative(outDir, entry.output).replace(/\.[^/.]+$/, "")
|
|
599
|
+
}), {}), exportIds = _exports && Object.keys(_exports).map((exportPath) => path.join(pkg.name, exportPath)), sourcePaths = _exports && Object.values(_exports).map((e) => path.resolve(cwd, e.source)), replacements = Object.fromEntries(
|
|
600
|
+
Object.entries(config?.define || {}).map(([key, val]) => [key, JSON.stringify(val)])
|
|
601
|
+
), { optimizeLodash: enableOptimizeLodash = hasDependency(pkg, "lodash") } = config?.rollup || {}, defaultPlugins = [
|
|
602
|
+
replace({
|
|
603
|
+
preventAssignment: !0,
|
|
604
|
+
values: pkg.name === "@sanity/pkg-utils" ? { ...replacements } : {
|
|
605
|
+
"process.env.PKG_FILE_PATH": (arg) => {
|
|
606
|
+
const sourcePath = `./${path.relative(cwd, arg)}`, entry = entries.find((e) => e.source === sourcePath);
|
|
607
|
+
return entry ? JSON.stringify(
|
|
608
|
+
path.relative(cwd, path.resolve(outDir, entry.name + outputExt))
|
|
609
|
+
) : (console.error(`could not find source entry: ${sourcePath}`), "null");
|
|
610
|
+
},
|
|
611
|
+
"process.env.PKG_FORMAT": JSON.stringify(format),
|
|
612
|
+
"process.env.PKG_RUNTIME": JSON.stringify(runtime),
|
|
613
|
+
"process.env.PKG_VERSION": JSON.stringify(process.env.PKG_VERSION || pkg.version),
|
|
614
|
+
...replacements
|
|
615
|
+
}
|
|
616
|
+
}),
|
|
617
|
+
alias({
|
|
618
|
+
entries: { ...pathAliases }
|
|
619
|
+
}),
|
|
620
|
+
nodeResolve({
|
|
621
|
+
browser: runtime === "browser",
|
|
622
|
+
extensions: [".cjs", ".mjs", ".js", ".jsx", ".json", ".node"],
|
|
623
|
+
preferBuiltins: !0
|
|
624
|
+
}),
|
|
625
|
+
commonjs(),
|
|
626
|
+
json(),
|
|
627
|
+
(config?.babel?.reactCompiler || config?.babel?.styledComponents) && babel({
|
|
628
|
+
babelrc: !1,
|
|
629
|
+
presets: ["@babel/preset-typescript"],
|
|
630
|
+
babelHelpers: "bundled",
|
|
631
|
+
extensions: [".ts", ".tsx", ".js", ".jsx"],
|
|
632
|
+
plugins: [
|
|
633
|
+
// The styled-components plugin needs to run before the react-compiler plugin, in case the css prop is used
|
|
634
|
+
config?.babel?.styledComponents && [
|
|
635
|
+
"babel-plugin-styled-components",
|
|
636
|
+
{
|
|
637
|
+
// Unnecessary, as the way we use styled-components in Sanity is usually by wrapping `@sanity/ui` primitives, not declaring new ones like "const Button = styled.button``"
|
|
638
|
+
fileName: !1,
|
|
639
|
+
// Native template literals take less space than this transpilation
|
|
640
|
+
transpileTemplateLiterals: !1,
|
|
641
|
+
// Massively helps dead code elimination and tree-shaking
|
|
642
|
+
pure: !0,
|
|
643
|
+
// disabled, as pkg-utils tends to be used for npm publishing, while other tooling, like `sanity dev`, `next dev`, etc are used for testing
|
|
644
|
+
cssProp: !1,
|
|
645
|
+
...typeof config.babel.styledComponents == "object" ? config.babel.styledComponents : {}
|
|
646
|
+
}
|
|
647
|
+
],
|
|
648
|
+
config?.babel?.reactCompiler && [
|
|
649
|
+
"babel-plugin-react-compiler",
|
|
650
|
+
config?.reactCompilerOptions || {}
|
|
651
|
+
]
|
|
652
|
+
].filter(Boolean)
|
|
653
|
+
}),
|
|
654
|
+
esbuild({
|
|
655
|
+
jsx: config?.jsx ?? "automatic",
|
|
656
|
+
jsxFactory: config?.jsxFactory ?? "createElement",
|
|
657
|
+
jsxFragment: config?.jsxFragment ?? "Fragment",
|
|
658
|
+
jsxImportSource: config?.jsxImportSource ?? "react",
|
|
659
|
+
target,
|
|
660
|
+
tsconfig: ctx.ts.configPath || "tsconfig.json",
|
|
661
|
+
treeShaking: !0,
|
|
662
|
+
minifySyntax: config?.minify !== !1,
|
|
663
|
+
supported: {
|
|
664
|
+
"template-literal": !0
|
|
665
|
+
}
|
|
666
|
+
}),
|
|
667
|
+
Array.isArray(config?.babel?.plugins) && getBabelOutputPlugin({
|
|
668
|
+
babelrc: !1,
|
|
669
|
+
plugins: config.babel.plugins
|
|
670
|
+
}),
|
|
671
|
+
enableOptimizeLodash && optimizeLodashImports({
|
|
672
|
+
useLodashEs: format === "esm" && hasDependency(pkg, "lodash-es") ? !0 : void 0,
|
|
673
|
+
...typeof config?.rollup?.optimizeLodash == "boolean" ? {} : config?.rollup?.optimizeLodash
|
|
674
|
+
}),
|
|
675
|
+
minify && terser({
|
|
676
|
+
compress: { directives: !1, passes: 10 },
|
|
677
|
+
ecma: 2020,
|
|
678
|
+
output: {
|
|
679
|
+
comments: (_node, comment) => {
|
|
680
|
+
const text = comment.value;
|
|
681
|
+
return comment.type === "comment2" ? /@preserve|@license|@cc_on/i.test(text) : !1;
|
|
682
|
+
},
|
|
683
|
+
preserve_annotations: !0
|
|
684
|
+
}
|
|
685
|
+
})
|
|
686
|
+
].filter(Boolean), userPlugins = config?.rollup?.plugins, plugins = Array.isArray(userPlugins) ? defaultPlugins.concat(userPlugins) : resolveConfigProperty(config?.rollup?.plugins, defaultPlugins), hashChunkFileNames = config?.rollup?.hashChunkFileNames ?? !1, chunkFileNames = `${hashChunkFileNames ? "_chunks" : "_chunks-[format]"}/${hashChunkFileNames ? "[name]-[hash]" : "[name]"}${outputExt}`, entryFileNames = `[name]${outputExt}`;
|
|
687
|
+
return {
|
|
688
|
+
inputOptions: {
|
|
689
|
+
context: cwd,
|
|
690
|
+
external: (id, importer) => {
|
|
691
|
+
if (exportIds?.includes(id))
|
|
692
|
+
return !0;
|
|
693
|
+
if (importer && (id.startsWith(".") || id.startsWith("/"))) {
|
|
694
|
+
const idPath = path.resolve(path.dirname(importer), id);
|
|
695
|
+
if (sourcePaths?.includes(idPath))
|
|
696
|
+
return logger.warn(
|
|
697
|
+
`detected self-referencing import \u2013 treating as external: ${path.relative(
|
|
698
|
+
cwd,
|
|
699
|
+
idPath
|
|
700
|
+
)}`
|
|
701
|
+
), !0;
|
|
702
|
+
}
|
|
703
|
+
const idParts = id.split("/"), name = idParts[0].startsWith("@") ? `${idParts[0]}/${idParts[1]}` : idParts[0];
|
|
704
|
+
return !!(name && external.includes(name));
|
|
705
|
+
},
|
|
706
|
+
input: entries.reduce(
|
|
707
|
+
(acc, entry) => Object.assign(acc, { [entry.name]: entry.source }),
|
|
708
|
+
{}
|
|
709
|
+
),
|
|
710
|
+
watch: {
|
|
711
|
+
chokidar: {
|
|
712
|
+
usePolling: !0
|
|
713
|
+
}
|
|
714
|
+
},
|
|
715
|
+
plugins,
|
|
716
|
+
treeshake: {
|
|
717
|
+
preset: "recommended",
|
|
718
|
+
propertyReadSideEffects: !1,
|
|
719
|
+
moduleSideEffects: "no-external",
|
|
720
|
+
...config?.rollup?.treeshake
|
|
721
|
+
},
|
|
722
|
+
experimentalLogSideEffects: config?.rollup?.experimentalLogSideEffects
|
|
723
|
+
},
|
|
724
|
+
outputOptions: {
|
|
725
|
+
chunkFileNames,
|
|
726
|
+
compact: minify,
|
|
727
|
+
dir: outDir,
|
|
728
|
+
entryFileNames,
|
|
729
|
+
esModule: !0,
|
|
730
|
+
format,
|
|
731
|
+
interop: "compat",
|
|
732
|
+
sourcemap: config?.sourcemap ?? !0,
|
|
733
|
+
hoistTransitiveImports: !1,
|
|
734
|
+
minifyInternalExports: minify,
|
|
735
|
+
...config?.rollup?.output
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
function hasDependency(pkg, packageName) {
|
|
740
|
+
return pkg.dependencies ? packageName in pkg.dependencies : pkg.peerDependencies ? packageName in pkg.peerDependencies : !1;
|
|
741
|
+
}
|
|
742
|
+
const rollupTask = {
|
|
743
|
+
name: (ctx, task) => {
|
|
744
|
+
const bundleEntries = task.entries.filter((e) => e.path.includes("__$$bundle_")), entries = task.entries.filter((e) => !e.path.includes("__$$bundle_")), targetLines = task.target.length ? [" target:", ...task.target.map((t) => ` - ${chalk.yellow(t)}`)] : [], bundlesLines = bundleEntries.length ? [
|
|
745
|
+
" bundles:",
|
|
746
|
+
...bundleEntries.map(
|
|
747
|
+
(e) => [
|
|
748
|
+
" - ",
|
|
749
|
+
`${chalk.yellow(e.source)} ${chalk.gray("\u2192")} ${chalk.yellow(e.output)}`
|
|
750
|
+
].join("")
|
|
751
|
+
)
|
|
752
|
+
] : [], entriesLines = entries.length ? [
|
|
753
|
+
" entries:",
|
|
754
|
+
...entries.map(
|
|
755
|
+
(e) => [
|
|
756
|
+
" - ",
|
|
757
|
+
`${chalk.cyan(path.join(ctx.pkg.name, e.path))}: `,
|
|
758
|
+
`${chalk.yellow(e.source)} ${chalk.gray("\u2192")} ${chalk.yellow(e.output)}`
|
|
759
|
+
].join("")
|
|
760
|
+
)
|
|
761
|
+
] : [];
|
|
762
|
+
return [
|
|
763
|
+
"Build javascript files...",
|
|
764
|
+
` format: ${chalk.yellow(task.format)}`,
|
|
765
|
+
...targetLines,
|
|
766
|
+
...bundlesLines,
|
|
767
|
+
...entriesLines
|
|
768
|
+
].join(`
|
|
769
|
+
`);
|
|
770
|
+
},
|
|
771
|
+
exec: (ctx, task) => new Observable((observer) => {
|
|
772
|
+
execPromise(ctx, task).then((result) => {
|
|
773
|
+
observer.next(result), observer.complete();
|
|
774
|
+
}).catch((err) => observer.error(err));
|
|
775
|
+
}),
|
|
776
|
+
complete: () => {
|
|
777
|
+
},
|
|
778
|
+
error: (_ctx, _task, err) => {
|
|
779
|
+
console.error(err);
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
async function execPromise(ctx, task) {
|
|
783
|
+
const { distPath, files, logger } = ctx, outDir = path.relative(ctx.cwd, distPath), consoleSpy = createConsoleSpy({
|
|
784
|
+
onRestored: (messages) => {
|
|
785
|
+
for (const msg of messages) {
|
|
786
|
+
const text = String(msg.args[0]);
|
|
787
|
+
msg.code !== "CIRCULAR_DEPENDENCY" && (text.startsWith("Dynamic import can only") || text.startsWith("Sourcemap is likely to be incorrect") || (msg.type === "log" && logger.info(...msg.args), msg.type === "warn" && logger.warn(...msg.args), msg.type === "error" && logger.error(...msg.args)));
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
});
|
|
791
|
+
try {
|
|
792
|
+
const { inputOptions, outputOptions } = resolveRollupConfig(ctx, task), bundle = await rollup({
|
|
793
|
+
...inputOptions,
|
|
794
|
+
onwarn(warning) {
|
|
795
|
+
consoleSpy.messages.push({
|
|
796
|
+
type: "warn",
|
|
797
|
+
code: warning.code,
|
|
798
|
+
args: [warning.message]
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
}), { output } = await bundle.generate(outputOptions);
|
|
802
|
+
for (const chunkOrAsset of output)
|
|
803
|
+
chunkOrAsset.type === "asset" ? files.push({
|
|
804
|
+
type: "asset",
|
|
805
|
+
path: path.resolve(outDir, chunkOrAsset.fileName)
|
|
806
|
+
}) : files.push({
|
|
807
|
+
type: "chunk",
|
|
808
|
+
path: path.resolve(outDir, chunkOrAsset.fileName)
|
|
809
|
+
});
|
|
810
|
+
await bundle.write(outputOptions), await bundle.close(), consoleSpy.restore();
|
|
811
|
+
} catch (err) {
|
|
812
|
+
throw consoleSpy.restore(), err;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
const rollupWatchTask = {
|
|
816
|
+
name: (ctx, task) => `build javascript files (target ${task.target.join(" + ")}, format ${task.format})
|
|
817
|
+
${task.entries.map((e) => `${chalk.blue(path.join(ctx.pkg.name, e.path))}: ${e.source} -> ${e.output}`).join(`
|
|
818
|
+
`)}`,
|
|
819
|
+
exec: (ctx, task) => {
|
|
820
|
+
const { inputOptions, outputOptions } = resolveRollupConfig(ctx, task);
|
|
821
|
+
return new Observable((observer) => {
|
|
822
|
+
const watchOptions = {
|
|
823
|
+
...inputOptions,
|
|
824
|
+
output: outputOptions
|
|
825
|
+
}, watcher = watch(watchOptions);
|
|
826
|
+
return watcher.on("event", (event) => {
|
|
827
|
+
observer.next(event);
|
|
828
|
+
}), () => {
|
|
829
|
+
watcher.close();
|
|
830
|
+
};
|
|
831
|
+
});
|
|
832
|
+
},
|
|
833
|
+
complete: (ctx, task, event) => {
|
|
834
|
+
const { logger } = ctx;
|
|
835
|
+
if (event.code === "BUNDLE_END") {
|
|
836
|
+
logger.success(
|
|
837
|
+
`build javascript files (target ${task.target.join(" + ")}, format ${task.format})
|
|
838
|
+
${task.entries.map((e) => `${chalk.blue(path.join(ctx.pkg.name, e.path))}: ${e.source} -> ${e.output}`).join(`
|
|
839
|
+
`)}`
|
|
840
|
+
), logger.log("");
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
843
|
+
if (event.code !== "BUNDLE_START" && event.code !== "END" && event.code === "ERROR") {
|
|
844
|
+
logger.error(event.code, event);
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
847
|
+
},
|
|
848
|
+
error: (ctx, _task, err) => {
|
|
849
|
+
const { logger } = ctx;
|
|
850
|
+
err instanceof Error && logger.log(err);
|
|
851
|
+
}
|
|
852
|
+
}, buildTaskHandlers = {
|
|
853
|
+
"build:dts": dtsTask,
|
|
854
|
+
"build:js": rollupTask,
|
|
855
|
+
"rolldown:dts": rolldownDtsTask
|
|
856
|
+
}, watchTaskHandlers = {
|
|
857
|
+
"watch:dts": dtsWatchTask,
|
|
858
|
+
"watch:js": rollupWatchTask
|
|
859
|
+
};
|
|
262
860
|
export {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
861
|
+
buildTaskHandlers,
|
|
862
|
+
createApiExtractorConfig$1 as createApiExtractorConfig,
|
|
863
|
+
createTSDocConfig$1 as createTSDocConfig,
|
|
266
864
|
getExtractMessagesConfig,
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
parseStrictOptions,
|
|
271
|
-
pkgExtMap,
|
|
272
|
-
strictOptions,
|
|
273
|
-
toggle
|
|
865
|
+
getExtractMessagesConfig$1,
|
|
866
|
+
printExtractMessages$1 as printExtractMessages,
|
|
867
|
+
watchTaskHandlers
|
|
274
868
|
};
|
|
275
869
|
//# sourceMappingURL=index.js.map
|