@sanity/pkg-utils 1.7.1 → 1.7.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/dist/{__resolveBuildContext-49ce07ba.cjs → __resolveBuildContext-56b6b816.cjs} +214 -102
- package/dist/__resolveBuildContext-56b6b816.cjs.map +1 -0
- package/dist/_build-49dd667f.cjs +208 -0
- package/dist/_build-49dd667f.cjs.map +1 -0
- package/dist/{_buildAction-38c3d2ed.cjs → _buildAction-b58e3a4b.cjs} +33 -6
- package/dist/_buildAction-b58e3a4b.cjs.map +1 -0
- package/dist/{_check-4ce1387d.cjs → _check-0871d90f.cjs} +112 -51
- package/dist/_check-0871d90f.cjs.map +1 -0
- package/dist/{_checkAction-2704266e.cjs → _checkAction-0510605b.cjs} +17 -3
- package/dist/_checkAction-0510605b.cjs.map +1 -0
- package/dist/_index-e3dda92a.cjs +733 -0
- package/dist/_index-e3dda92a.cjs.map +1 -0
- package/dist/_watch-e1c86797.cjs +267 -0
- package/dist/_watch-e1c86797.cjs.map +1 -0
- package/dist/{_watchAction-df30594b.cjs → _watchAction-cfe36cbc.cjs} +36 -6
- package/dist/_watchAction-cfe36cbc.cjs.map +1 -0
- package/dist/cli.cjs +24 -9
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +45 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +792 -516
- package/dist/index.js.map +1 -1
- package/dist/types/src/cli/buildAction.d.ts +4 -0
- package/dist/types/src/cli/buildAction.d.ts.map +1 -0
- package/dist/types/src/cli/checkAction.d.ts +5 -0
- package/dist/types/src/cli/checkAction.d.ts.map +1 -0
- package/dist/types/src/cli/index.d.ts +2 -0
- package/dist/types/src/cli/index.d.ts.map +1 -0
- package/dist/types/src/cli/watchAction.d.ts +4 -0
- package/dist/types/src/cli/watchAction.d.ts.map +1 -0
- package/dist/types/src/node/_core/_defaults.d.ts +5 -0
- package/dist/types/src/node/_core/_defaults.d.ts.map +1 -0
- package/dist/types/src/node/_core/_isRecord.d.ts +3 -0
- package/dist/types/src/node/_core/_isRecord.d.ts.map +1 -0
- package/dist/types/src/node/_core/config/_loadConfig.d.ts +6 -0
- package/dist/types/src/node/_core/config/_loadConfig.d.ts.map +1 -0
- package/dist/types/src/node/_core/config/_resolveConfigProperty.d.ts +4 -0
- package/dist/types/src/node/_core/config/_resolveConfigProperty.d.ts.map +1 -0
- package/dist/types/src/node/_core/config/defineConfig.d.ts +4 -0
- package/dist/types/src/node/_core/config/defineConfig.d.ts.map +1 -0
- package/dist/types/src/node/_core/config/index.d.ts +5 -0
- package/dist/types/src/node/_core/config/index.d.ts.map +1 -0
- package/dist/types/src/node/_core/config/types.d.ts +76 -0
- package/dist/types/src/node/_core/config/types.d.ts.map +1 -0
- package/dist/types/src/node/_core/contexts/buildContext.d.ts +33 -0
- package/dist/types/src/node/_core/contexts/buildContext.d.ts.map +1 -0
- package/dist/types/src/node/_core/contexts/index.d.ts +2 -0
- package/dist/types/src/node/_core/contexts/index.d.ts.map +1 -0
- package/dist/types/src/node/_core/index.d.ts +7 -0
- package/dist/types/src/node/_core/index.d.ts.map +1 -0
- package/dist/types/src/node/_core/pkg/_loadPkg.d.ts +6 -0
- package/dist/types/src/node/_core/pkg/_loadPkg.d.ts.map +1 -0
- package/dist/types/src/node/_core/pkg/_loadPkgWithReporting.d.ts +6 -0
- package/dist/types/src/node/_core/pkg/_loadPkgWithReporting.d.ts.map +1 -0
- package/dist/types/src/node/_core/pkg/_parseExports.d.ts +9 -0
- package/dist/types/src/node/_core/pkg/_parseExports.d.ts.map +1 -0
- package/dist/types/src/node/_core/pkg/_types.d.ts +29 -0
- package/dist/types/src/node/_core/pkg/_types.d.ts.map +1 -0
- package/dist/types/src/node/_core/pkg/index.d.ts +5 -0
- package/dist/types/src/node/_core/pkg/index.d.ts.map +1 -0
- package/dist/types/src/node/_core/ts/_loadTSConfig.d.ts +7 -0
- package/dist/types/src/node/_core/ts/_loadTSConfig.d.ts.map +1 -0
- package/dist/types/src/node/_core/ts/index.d.ts +2 -0
- package/dist/types/src/node/_core/ts/index.d.ts.map +1 -0
- package/dist/types/src/node/_getFilesize.d.ts +2 -0
- package/dist/types/src/node/_getFilesize.d.ts.map +1 -0
- package/dist/types/src/node/_globFiles.d.ts +2 -0
- package/dist/types/src/node/_globFiles.d.ts.map +1 -0
- package/dist/types/src/node/_printExtractMessages.d.ts +4 -0
- package/dist/types/src/node/_printExtractMessages.d.ts.map +1 -0
- package/dist/types/src/node/_printPackageTree.d.ts +4 -0
- package/dist/types/src/node/_printPackageTree.d.ts.map +1 -0
- package/dist/types/src/node/_resolveBrowserTarget.d.ts +3 -0
- package/dist/types/src/node/_resolveBrowserTarget.d.ts.map +1 -0
- package/dist/types/src/node/_resolveBrowserslistVersions.d.ts +11 -0
- package/dist/types/src/node/_resolveBrowserslistVersions.d.ts.map +1 -0
- package/dist/types/src/node/_resolveBuildContext.d.ts +8 -0
- package/dist/types/src/node/_resolveBuildContext.d.ts.map +1 -0
- package/dist/types/src/node/_resolveBuildTasks.d.ts +5 -0
- package/dist/types/src/node/_resolveBuildTasks.d.ts.map +1 -0
- package/dist/types/src/node/_resolveNodeTarget.d.ts +3 -0
- package/dist/types/src/node/_resolveNodeTarget.d.ts.map +1 -0
- package/dist/types/src/node/_resolveWatchTasks.d.ts +5 -0
- package/dist/types/src/node/_resolveWatchTasks.d.ts.map +1 -0
- package/dist/types/src/node/_spinner.d.ts +5 -0
- package/dist/types/src/node/_spinner.d.ts.map +1 -0
- package/dist/types/src/node/_tasks/_types.d.ts +50 -0
- package/dist/types/src/node/_tasks/_types.d.ts.map +1 -0
- package/dist/types/src/node/_tasks/dts/_DtsError.d.ts +7 -0
- package/dist/types/src/node/_tasks/dts/_DtsError.d.ts.map +1 -0
- package/dist/types/src/node/_tasks/dts/_buildTypes.d.ts +9 -0
- package/dist/types/src/node/_tasks/dts/_buildTypes.d.ts.map +1 -0
- package/dist/types/src/node/_tasks/dts/_createApiExtractorConfig.d.ts +11 -0
- package/dist/types/src/node/_tasks/dts/_createApiExtractorConfig.d.ts.map +1 -0
- package/dist/types/src/node/_tasks/dts/_createTSDocConfig.d.ts +12 -0
- package/dist/types/src/node/_tasks/dts/_createTSDocConfig.d.ts.map +1 -0
- package/dist/types/src/node/_tasks/dts/_doExtract.d.ts +4 -0
- package/dist/types/src/node/_tasks/dts/_doExtract.d.ts.map +1 -0
- package/dist/types/src/node/_tasks/dts/_dtsTask.d.ts +5 -0
- package/dist/types/src/node/_tasks/dts/_dtsTask.d.ts.map +1 -0
- package/dist/types/src/node/_tasks/dts/_dtsWatchTask.d.ts +5 -0
- package/dist/types/src/node/_tasks/dts/_dtsWatchTask.d.ts.map +1 -0
- package/dist/types/src/node/_tasks/dts/_extractTypes.d.ts +17 -0
- package/dist/types/src/node/_tasks/dts/_extractTypes.d.ts.map +1 -0
- package/dist/types/src/node/_tasks/dts/_types.d.ts +27 -0
- package/dist/types/src/node/_tasks/dts/_types.d.ts.map +1 -0
- package/dist/types/src/node/_tasks/dts/index.d.ts +4 -0
- package/dist/types/src/node/_tasks/dts/index.d.ts.map +1 -0
- package/dist/types/src/node/_tasks/index.d.ts +9 -0
- package/dist/types/src/node/_tasks/index.d.ts.map +1 -0
- package/dist/types/src/node/_tasks/rollup/_resolveRollupConfig.d.ts +10 -0
- package/dist/types/src/node/_tasks/rollup/_resolveRollupConfig.d.ts.map +1 -0
- package/dist/types/src/node/_tasks/rollup/_rollupTask.d.ts +4 -0
- package/dist/types/src/node/_tasks/rollup/_rollupTask.d.ts.map +1 -0
- package/dist/types/src/node/_tasks/rollup/_rollupWatchTask.d.ts +5 -0
- package/dist/types/src/node/_tasks/rollup/_rollupWatchTask.d.ts.map +1 -0
- package/dist/types/src/node/_tasks/rollup/index.d.ts +3 -0
- package/dist/types/src/node/_tasks/rollup/index.d.ts.map +1 -0
- package/dist/types/src/node/_watchConfigFiles.d.ts +5 -0
- package/dist/types/src/node/_watchConfigFiles.d.ts.map +1 -0
- package/dist/types/src/node/_watchFiles.d.ts +7 -0
- package/dist/types/src/node/_watchFiles.d.ts.map +1 -0
- package/dist/types/src/node/build.d.ts +6 -0
- package/dist/types/src/node/build.d.ts.map +1 -0
- package/dist/types/src/node/check.d.ts +7 -0
- package/dist/types/src/node/check.d.ts.map +1 -0
- package/dist/{index.d.ts → types/src/node/index.d.ts} +12 -8
- package/dist/types/src/node/index.d.ts.map +1 -0
- package/dist/types/src/node/watch.d.ts +6 -0
- package/dist/types/src/node/watch.d.ts.map +1 -0
- package/package.json +16 -9
- package/src/node/_core/config/_loadConfig.ts +5 -0
- package/src/node/_core/pkg/_loadPkgWithReporting.ts +1 -1
- package/src/node/_resolveBuildTasks.ts +19 -17
- package/src/node/_resolveWatchTasks.ts +20 -18
- package/src/node/_tasks/dts/_buildTypes.ts +2 -25
- package/src/node/_tasks/dts/_doExtract.ts +32 -31
- package/src/node/_tasks/dts/_dtsTask.ts +4 -1
- package/src/node/_tasks/dts/_dtsWatchTask.ts +4 -1
- package/src/node/_tasks/dts/_types.ts +12 -8
- package/src/node/_tasks/rollup/_resolveRollupConfig.ts +56 -6
- package/src/node/build.ts +0 -1
- package/dist/__resolveBuildContext-49ce07ba.cjs.map +0 -1
- package/dist/_build-9e9eb450.cjs +0 -159
- package/dist/_build-9e9eb450.cjs.map +0 -1
- package/dist/_buildAction-38c3d2ed.cjs.map +0 -1
- package/dist/_check-4ce1387d.cjs.map +0 -1
- package/dist/_checkAction-2704266e.cjs.map +0 -1
- package/dist/_index-0e8b664d.cjs +0 -607
- package/dist/_index-0e8b664d.cjs.map +0 -1
- package/dist/_watch-fca55d1f.cjs +0 -219
- package/dist/_watch-fca55d1f.cjs.map +0 -1
- package/dist/_watchAction-df30594b.cjs.map +0 -1
- package/src/node/_resolveEsTarget.ts +0 -39
package/dist/index.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
const _excluded = ["_path"];
|
|
2
|
+
|
|
3
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
|
+
|
|
5
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
6
|
+
|
|
7
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
8
|
+
|
|
9
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
10
|
+
|
|
11
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
+
|
|
1
13
|
import path from 'path';
|
|
2
14
|
import { register } from 'esbuild-register/dist/node';
|
|
3
15
|
import findConfig from 'find-config';
|
|
@@ -8,8 +20,6 @@ import chalk from 'chalk';
|
|
|
8
20
|
import ts from 'typescript';
|
|
9
21
|
import fs$1, { statSync } from 'fs';
|
|
10
22
|
import { Observable, switchMap } from 'rxjs';
|
|
11
|
-
import { promisify } from 'util';
|
|
12
|
-
import rimrafCallback from 'rimraf';
|
|
13
23
|
import { ExtractorConfig, Extractor } from '@microsoft/api-extractor';
|
|
14
24
|
import mkdirp from 'mkdirp';
|
|
15
25
|
import prettier from 'prettier';
|
|
@@ -17,11 +27,13 @@ import { TSDocConfigFile } from '@microsoft/tsdoc-config';
|
|
|
17
27
|
import { parse } from 'jsonc-parser';
|
|
18
28
|
import { rollup, watch as watch$1 } from 'rollup';
|
|
19
29
|
import alias from '@rollup/plugin-alias';
|
|
30
|
+
import { getBabelOutputPlugin } from '@rollup/plugin-babel';
|
|
20
31
|
import commonjs from '@rollup/plugin-commonjs';
|
|
21
32
|
import json from '@rollup/plugin-json';
|
|
22
33
|
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
23
34
|
import replace from '@rollup/plugin-replace';
|
|
24
35
|
import esbuild from 'rollup-plugin-esbuild';
|
|
36
|
+
import { terser } from 'rollup-plugin-terser';
|
|
25
37
|
import browserslist from 'browserslist';
|
|
26
38
|
import esbuild$1 from 'esbuild';
|
|
27
39
|
import treeify from 'treeify';
|
|
@@ -29,14 +41,8 @@ import prettyBytes from 'pretty-bytes';
|
|
|
29
41
|
import { scan, startWith, distinctUntilChanged } from 'rxjs/operators';
|
|
30
42
|
import globby from 'globby';
|
|
31
43
|
import chokidar from 'chokidar';
|
|
32
|
-
|
|
33
44
|
const _DEFAULTS = {
|
|
34
|
-
browserslist: [
|
|
35
|
-
"> 0.2% and supports es6-module and supports es6-module-dynamic-import",
|
|
36
|
-
"not dead",
|
|
37
|
-
"not IE 11",
|
|
38
|
-
"maintained node versions"
|
|
39
|
-
]
|
|
45
|
+
browserslist: ["> 0.2% and supports es6-module and supports es6-module-dynamic-import", "not dead", "not IE 11", "maintained node versions"]
|
|
40
46
|
};
|
|
41
47
|
|
|
42
48
|
function _isRecord(value) {
|
|
@@ -44,40 +50,68 @@ function _isRecord(value) {
|
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
async function _loadConfig(options) {
|
|
47
|
-
const {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
const {
|
|
54
|
+
cwd
|
|
55
|
+
} = options;
|
|
56
|
+
const pkgPath = await pkgUp({
|
|
57
|
+
cwd
|
|
58
|
+
});
|
|
59
|
+
if (!pkgPath) return void 0;
|
|
51
60
|
const root = path.dirname(pkgPath);
|
|
61
|
+
|
|
52
62
|
const configFile = _findConfigFile(root);
|
|
63
|
+
|
|
53
64
|
if (!configFile) {
|
|
54
65
|
return void 0;
|
|
55
66
|
}
|
|
67
|
+
|
|
68
|
+
if (!configFile.path.startsWith(cwd)) {
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
|
|
56
72
|
try {
|
|
57
|
-
const {
|
|
73
|
+
const {
|
|
74
|
+
unregister
|
|
75
|
+
} = configFile.transform ? register({
|
|
76
|
+
extensions: [".js", ".ts"]
|
|
77
|
+
}) : {
|
|
78
|
+
unregister: () => void 0
|
|
79
|
+
};
|
|
80
|
+
|
|
58
81
|
const mod = require(configFile.path);
|
|
82
|
+
|
|
59
83
|
unregister();
|
|
60
84
|
return (mod == null ? void 0 : mod.default) || mod || void 0;
|
|
61
85
|
} catch (_) {
|
|
62
86
|
return void 0;
|
|
63
87
|
}
|
|
64
88
|
}
|
|
89
|
+
|
|
65
90
|
function _findConfigFile(cwd) {
|
|
66
|
-
const ts = findConfig("package.config.ts", {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
91
|
+
const ts = findConfig("package.config.ts", {
|
|
92
|
+
cwd
|
|
93
|
+
});
|
|
94
|
+
if (ts) return {
|
|
95
|
+
path: ts,
|
|
96
|
+
transform: true
|
|
97
|
+
};
|
|
98
|
+
const cjs = findConfig("package.config.cjs", {
|
|
99
|
+
cwd
|
|
100
|
+
});
|
|
101
|
+
if (cjs) return {
|
|
102
|
+
path: cjs,
|
|
103
|
+
transform: false
|
|
104
|
+
};
|
|
72
105
|
return null;
|
|
73
106
|
}
|
|
74
107
|
|
|
75
108
|
function _resolveConfigProperty(prop, initialValue) {
|
|
76
|
-
if (!prop)
|
|
77
|
-
|
|
109
|
+
if (!prop) return initialValue;
|
|
110
|
+
|
|
78
111
|
if (typeof prop === "function") {
|
|
79
112
|
return prop(initialValue);
|
|
80
113
|
}
|
|
114
|
+
|
|
81
115
|
return prop;
|
|
82
116
|
}
|
|
83
117
|
|
|
@@ -98,36 +132,32 @@ const pkgSchema = z.object({
|
|
|
98
132
|
browser: z.optional(z.record(z.string())),
|
|
99
133
|
module: z.optional(z.string()),
|
|
100
134
|
types: z.optional(z.string()),
|
|
101
|
-
exports: z.optional(
|
|
102
|
-
z.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
})
|
|
117
|
-
),
|
|
118
|
-
require: z.optional(z.string()),
|
|
119
|
-
import: z.optional(z.string()),
|
|
120
|
-
default: z.string()
|
|
121
|
-
})
|
|
122
|
-
)
|
|
123
|
-
),
|
|
135
|
+
exports: z.optional(z.record(z.object({
|
|
136
|
+
types: z.optional(z.string()),
|
|
137
|
+
source: z.string(),
|
|
138
|
+
browser: z.optional(z.object({
|
|
139
|
+
require: z.optional(z.string()),
|
|
140
|
+
import: z.optional(z.string())
|
|
141
|
+
})),
|
|
142
|
+
node: z.optional(z.object({
|
|
143
|
+
require: z.optional(z.string()),
|
|
144
|
+
import: z.optional(z.string())
|
|
145
|
+
})),
|
|
146
|
+
require: z.optional(z.string()),
|
|
147
|
+
import: z.optional(z.string()),
|
|
148
|
+
default: z.string()
|
|
149
|
+
}))),
|
|
124
150
|
browserslist: z.optional(z.array(z.string()))
|
|
125
151
|
});
|
|
152
|
+
|
|
126
153
|
async function _loadPkg(options) {
|
|
127
|
-
const {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
154
|
+
const {
|
|
155
|
+
cwd
|
|
156
|
+
} = options;
|
|
157
|
+
const pkgPath = await pkgUp({
|
|
158
|
+
cwd
|
|
159
|
+
});
|
|
160
|
+
if (!pkgPath) throw new Error("no package.json found");
|
|
131
161
|
const buf = await fs.readFile(pkgPath);
|
|
132
162
|
return pkgSchema.parse(JSON.parse(buf.toString()));
|
|
133
163
|
}
|
|
@@ -139,22 +169,21 @@ async function _loadPkgWithReporting(options) {
|
|
|
139
169
|
if (err instanceof ZodError) {
|
|
140
170
|
for (const issue of err.issues) {
|
|
141
171
|
if (issue.code === "invalid_type") {
|
|
142
|
-
console.log(
|
|
143
|
-
`${chalk.red("invalid type")} in ./package.json at ${chalk.magenta(
|
|
144
|
-
`\`${issue.path.join("")}\``
|
|
145
|
-
)} (expected ${issue.expected}, received ${issue.received})`
|
|
146
|
-
);
|
|
172
|
+
console.log("".concat(chalk.red("invalid type"), " in ./package.json at ").concat(chalk.magenta("`".concat(issue.path.join("."), "`")), " (expected ").concat(issue.expected, ", received ").concat(issue.received, ")"));
|
|
147
173
|
}
|
|
148
174
|
}
|
|
149
175
|
} else {
|
|
150
176
|
console.error(err);
|
|
151
177
|
}
|
|
178
|
+
|
|
152
179
|
process.exit(1);
|
|
153
180
|
}
|
|
154
181
|
}
|
|
155
182
|
|
|
156
183
|
function _parseExports(options) {
|
|
157
|
-
const {
|
|
184
|
+
const {
|
|
185
|
+
pkg
|
|
186
|
+
} = options;
|
|
158
187
|
const rootExport = {
|
|
159
188
|
_exported: true,
|
|
160
189
|
_path: ".",
|
|
@@ -169,17 +198,18 @@ function _parseExports(options) {
|
|
|
169
198
|
default: pkg.module || pkg.main || "./index.js"
|
|
170
199
|
};
|
|
171
200
|
const extraExports = [];
|
|
201
|
+
|
|
172
202
|
if (pkg.exports) {
|
|
173
203
|
for (const [exportPath, exportEntry] of Object.entries(pkg.exports)) {
|
|
174
204
|
if (_isRecord(exportEntry)) {
|
|
175
205
|
if (exportPath === ".") {
|
|
176
206
|
Object.assign(rootExport, exportEntry);
|
|
177
207
|
} else {
|
|
178
|
-
const extraExport = {
|
|
208
|
+
const extraExport = _objectSpread({
|
|
179
209
|
_exported: true,
|
|
180
|
-
_path: exportPath
|
|
181
|
-
|
|
182
|
-
|
|
210
|
+
_path: exportPath
|
|
211
|
+
}, exportEntry);
|
|
212
|
+
|
|
183
213
|
extraExports.push(extraExport);
|
|
184
214
|
}
|
|
185
215
|
} else {
|
|
@@ -187,179 +217,171 @@ function _parseExports(options) {
|
|
|
187
217
|
}
|
|
188
218
|
}
|
|
189
219
|
}
|
|
220
|
+
|
|
190
221
|
return [rootExport, ...extraExports];
|
|
191
222
|
}
|
|
192
223
|
|
|
193
224
|
async function _loadTSConfig(options) {
|
|
194
|
-
const {
|
|
225
|
+
const {
|
|
226
|
+
cwd,
|
|
227
|
+
tsconfigPath
|
|
228
|
+
} = options;
|
|
195
229
|
const configPath = ts.findConfigFile(cwd, ts.sys.fileExists, tsconfigPath);
|
|
230
|
+
|
|
196
231
|
if (!configPath) {
|
|
197
|
-
throw new Error(
|
|
232
|
+
throw new Error("could not find a valid '".concat(tsconfigPath, "'"));
|
|
198
233
|
}
|
|
234
|
+
|
|
199
235
|
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
200
236
|
return ts.parseJsonConfigFileContent(configFile.config, ts.sys, cwd);
|
|
201
237
|
}
|
|
202
238
|
|
|
203
|
-
const TS_TARGETS = {
|
|
204
|
-
0: "es3",
|
|
205
|
-
1: "es5",
|
|
206
|
-
2: "es2015",
|
|
207
|
-
3: "es2016",
|
|
208
|
-
4: "es2017",
|
|
209
|
-
5: "es2018",
|
|
210
|
-
6: "es2019",
|
|
211
|
-
7: "es2020",
|
|
212
|
-
8: "es2021",
|
|
213
|
-
9: "es2022",
|
|
214
|
-
99: "esnext",
|
|
215
|
-
100: "esnext"
|
|
216
|
-
};
|
|
217
|
-
function _resolveEsTarget(ctx) {
|
|
218
|
-
var _a;
|
|
219
|
-
const { ts } = ctx;
|
|
220
|
-
const tsTarget = ((_a = ts.config) == null ? void 0 : _a.options.target) || 99;
|
|
221
|
-
return TS_TARGETS[tsTarget] || "esnext";
|
|
222
|
-
}
|
|
223
|
-
|
|
224
239
|
function _resolveBuildTasks(ctx) {
|
|
225
240
|
var _a, _b, _c, _d, _e;
|
|
226
|
-
|
|
227
|
-
const
|
|
241
|
+
|
|
242
|
+
const {
|
|
243
|
+
cwd,
|
|
244
|
+
pkg,
|
|
245
|
+
target
|
|
246
|
+
} = ctx;
|
|
228
247
|
const tasks = [];
|
|
229
|
-
const exports = Object.entries(ctx.exports || {}).map(
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
248
|
+
const exports = Object.entries(ctx.exports || {}).map(_ref => {
|
|
249
|
+
let [_path, exp] = _ref;
|
|
250
|
+
return _objectSpread({
|
|
251
|
+
_path
|
|
252
|
+
}, exp);
|
|
253
|
+
});
|
|
254
|
+
const dtsTask = {
|
|
255
|
+
type: "build:dts",
|
|
256
|
+
entries: []
|
|
257
|
+
};
|
|
233
258
|
const rollupTasks = {};
|
|
259
|
+
|
|
234
260
|
function _addRollupTaskEntry(format, runtime, entry) {
|
|
235
|
-
const buildId =
|
|
236
|
-
|
|
261
|
+
const buildId = "".concat(format, ":").concat(runtime);
|
|
262
|
+
|
|
263
|
+
if (rollupTasks[buildId]) {
|
|
264
|
+
rollupTasks[buildId].entries.push(entry);
|
|
265
|
+
} else {
|
|
237
266
|
rollupTasks[buildId] = {
|
|
238
267
|
type: "build:js",
|
|
239
268
|
buildId,
|
|
240
269
|
entries: [entry],
|
|
241
270
|
runtime,
|
|
242
271
|
format,
|
|
243
|
-
target:
|
|
272
|
+
target: target[runtime]
|
|
244
273
|
};
|
|
245
|
-
} else {
|
|
246
|
-
rollupTasks[buildId].entries.push(entry);
|
|
247
274
|
}
|
|
248
275
|
}
|
|
276
|
+
|
|
249
277
|
for (const exp of exports) {
|
|
250
278
|
const importId = path.join(pkg.name, exp._path);
|
|
279
|
+
|
|
251
280
|
if (exp.types) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
targetPath: exp.types
|
|
259
|
-
};
|
|
260
|
-
}
|
|
281
|
+
dtsTask.entries.push({
|
|
282
|
+
importId,
|
|
283
|
+
exportPath: exp._path,
|
|
284
|
+
sourcePath: exp.source,
|
|
285
|
+
targetPath: exp.types
|
|
286
|
+
});
|
|
261
287
|
}
|
|
262
288
|
}
|
|
289
|
+
|
|
263
290
|
for (const exp of exports) {
|
|
264
291
|
const output = exp.require;
|
|
265
|
-
if (!output)
|
|
266
|
-
|
|
292
|
+
if (!output) continue;
|
|
293
|
+
|
|
267
294
|
_addRollupTaskEntry("commonjs", ctx.runtime, {
|
|
268
295
|
path: exp._path,
|
|
269
296
|
source: exp.source,
|
|
270
297
|
output
|
|
271
298
|
});
|
|
272
299
|
}
|
|
300
|
+
|
|
273
301
|
for (const exp of exports) {
|
|
274
302
|
const output = (_a = exp.browser) == null ? void 0 : _a.require;
|
|
275
|
-
if (!output)
|
|
276
|
-
|
|
303
|
+
if (!output) continue;
|
|
304
|
+
|
|
277
305
|
_addRollupTaskEntry("commonjs", "browser", {
|
|
278
306
|
path: exp._path,
|
|
279
307
|
source: ((_b = exp.browser) == null ? void 0 : _b.source) || exp.source,
|
|
280
308
|
output
|
|
281
309
|
});
|
|
282
310
|
}
|
|
311
|
+
|
|
283
312
|
for (const exp of exports) {
|
|
284
313
|
const output = exp.import;
|
|
285
|
-
if (!output)
|
|
286
|
-
|
|
314
|
+
if (!output) continue;
|
|
315
|
+
|
|
287
316
|
_addRollupTaskEntry("esm", ctx.runtime, {
|
|
288
317
|
path: exp._path,
|
|
289
318
|
source: exp.source,
|
|
290
319
|
output
|
|
291
320
|
});
|
|
292
321
|
}
|
|
322
|
+
|
|
293
323
|
for (const exp of exports) {
|
|
294
324
|
const output = (_c = exp.browser) == null ? void 0 : _c.import;
|
|
295
|
-
if (!output)
|
|
296
|
-
|
|
325
|
+
if (!output) continue;
|
|
326
|
+
|
|
297
327
|
_addRollupTaskEntry("esm", "browser", {
|
|
298
328
|
path: exp._path,
|
|
299
329
|
source: ((_d = exp.browser) == null ? void 0 : _d.source) || exp.source,
|
|
300
330
|
output
|
|
301
331
|
});
|
|
302
332
|
}
|
|
303
|
-
|
|
333
|
+
|
|
334
|
+
if (dtsTask.entries.length) {
|
|
335
|
+
tasks.push(dtsTask);
|
|
336
|
+
}
|
|
337
|
+
|
|
304
338
|
tasks.push(...Object.values(rollupTasks));
|
|
339
|
+
|
|
305
340
|
for (const exp of exports) {
|
|
306
341
|
if (exp._exported && exp._path !== ".") {
|
|
307
342
|
const relativeTargetPath = (((_e = exp.browser) == null ? void 0 : _e.import) || exp.import || "").replace(/\.[^/.]+$/, "");
|
|
343
|
+
|
|
308
344
|
if (relativeTargetPath) {
|
|
309
|
-
fs$1.writeFileSync(
|
|
310
|
-
path.resolve(cwd, `${exp._path}.js`),
|
|
311
|
-
[
|
|
312
|
-
`// AUTO-GENERATED \u2013 DO NOT EDIT`,
|
|
313
|
-
``,
|
|
314
|
-
`export * from '${relativeTargetPath}'`,
|
|
315
|
-
``
|
|
316
|
-
].join("\n")
|
|
317
|
-
);
|
|
345
|
+
fs$1.writeFileSync(path.resolve(cwd, "".concat(exp._path, ".js")), ["// AUTO-GENERATED \u2013 DO NOT EDIT", "", "export * from '".concat(relativeTargetPath, "'"), ""].join("\n"));
|
|
318
346
|
}
|
|
319
347
|
}
|
|
320
348
|
}
|
|
349
|
+
|
|
321
350
|
return tasks;
|
|
322
351
|
}
|
|
323
352
|
|
|
324
353
|
function _printExtractMessages(ctx, messages) {
|
|
325
|
-
const {
|
|
326
|
-
|
|
354
|
+
const {
|
|
355
|
+
cwd,
|
|
356
|
+
logger
|
|
357
|
+
} = ctx;
|
|
358
|
+
const warnings = messages.filter(msg => msg.logLevel === "warning");
|
|
359
|
+
|
|
327
360
|
if (warnings.length) {
|
|
328
361
|
logger.log();
|
|
329
362
|
}
|
|
363
|
+
|
|
330
364
|
for (const msg of warnings) {
|
|
331
365
|
const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath);
|
|
366
|
+
|
|
332
367
|
if (msg.messageId === "TS6307") {
|
|
333
368
|
continue;
|
|
334
369
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
`${chalk.cyan(sourceFilePath || "?")}`,
|
|
338
|
-
`:${chalk.yellow(msg.sourceFileLine)}:${chalk.yellow(msg.sourceFileColumn)}`,
|
|
339
|
-
` - ${chalk.yellow("warning")} ${chalk.gray(msg.messageId)}
|
|
340
|
-
`,
|
|
341
|
-
msg.text,
|
|
342
|
-
"\n"
|
|
343
|
-
].join("")
|
|
344
|
-
);
|
|
370
|
+
|
|
371
|
+
logger.log(["".concat(chalk.cyan(sourceFilePath || "?")), ":".concat(chalk.yellow(msg.sourceFileLine), ":").concat(chalk.yellow(msg.sourceFileColumn)), " - ".concat(chalk.yellow("warning"), " ").concat(chalk.gray(msg.messageId), "\n"), msg.text, "\n"].join(""));
|
|
345
372
|
}
|
|
346
|
-
|
|
373
|
+
|
|
374
|
+
const errors = messages.filter(msg => msg.logLevel === "error");
|
|
375
|
+
|
|
347
376
|
if (!warnings.length && errors.length) {
|
|
348
377
|
logger.log("");
|
|
349
378
|
}
|
|
379
|
+
|
|
350
380
|
for (const msg of errors) {
|
|
351
381
|
const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath);
|
|
352
|
-
logger.log(
|
|
353
|
-
[
|
|
354
|
-
`${chalk.cyan(sourceFilePath || "?")}`,
|
|
355
|
-
`:${chalk.yellow(msg.sourceFileLine)}:${chalk.yellow(msg.sourceFileColumn)}`,
|
|
356
|
-
` - ${chalk.red("error")} ${chalk.gray(msg.messageId)}
|
|
357
|
-
`,
|
|
358
|
-
msg.text,
|
|
359
|
-
"\n"
|
|
360
|
-
].join("")
|
|
361
|
-
);
|
|
382
|
+
logger.log(["".concat(chalk.cyan(sourceFilePath || "?")), ":".concat(chalk.yellow(msg.sourceFileLine), ":").concat(chalk.yellow(msg.sourceFileColumn)), " - ".concat(chalk.red("error"), " ").concat(chalk.gray(msg.messageId), "\n"), msg.text, "\n"].join(""));
|
|
362
383
|
}
|
|
384
|
+
|
|
363
385
|
if (errors.length) {
|
|
364
386
|
process.exit(1);
|
|
365
387
|
}
|
|
@@ -368,49 +390,47 @@ function _printExtractMessages(ctx, messages) {
|
|
|
368
390
|
const formatHost = {
|
|
369
391
|
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
|
|
370
392
|
getNewLine: () => ts.sys.newLine,
|
|
371
|
-
getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ?
|
|
393
|
+
getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? f => f : f => f.toLowerCase()
|
|
372
394
|
};
|
|
395
|
+
|
|
373
396
|
async function _buildTypes(options) {
|
|
374
|
-
const {
|
|
375
|
-
|
|
376
|
-
|
|
397
|
+
const {
|
|
398
|
+
outDir,
|
|
399
|
+
tsconfig
|
|
400
|
+
} = options;
|
|
401
|
+
|
|
402
|
+
const compilerOptions = _objectSpread(_objectSpread({}, tsconfig.options), {}, {
|
|
377
403
|
declaration: true,
|
|
378
404
|
declarationDir: outDir,
|
|
379
405
|
emitDeclarationOnly: true,
|
|
380
406
|
noEmit: false,
|
|
381
407
|
outDir
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
cwd,
|
|
385
|
-
compilerOptions.rootDir ? path.resolve(cwd, compilerOptions.rootDir) : path.dirname(path.resolve(cwd, sourcePath))
|
|
386
|
-
) || ".";
|
|
408
|
+
});
|
|
409
|
+
|
|
387
410
|
const program = ts.createProgram(tsconfig.fileNames, compilerOptions);
|
|
388
|
-
const sourceFiles = program.getSourceFiles();
|
|
389
|
-
const sourceFile = sourceFiles.find((f) => f.fileName === path.resolve(cwd, sourcePath));
|
|
390
|
-
if (!sourceFile) {
|
|
391
|
-
throw new Error(`source file not found: ${sourcePath}`);
|
|
392
|
-
}
|
|
393
411
|
const emitResult = program.emit();
|
|
394
412
|
const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
395
|
-
allDiagnostics.forEach(
|
|
413
|
+
allDiagnostics.forEach(diagnostic => {
|
|
396
414
|
if (diagnostic.file && diagnostic.start) {
|
|
397
|
-
const {
|
|
415
|
+
const {
|
|
416
|
+
line,
|
|
417
|
+
character
|
|
418
|
+
} = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
|
398
419
|
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
399
|
-
console.log(
|
|
400
|
-
${message}`);
|
|
420
|
+
console.log("".concat(diagnostic.file.fileName, " ").concat(line + 1, ":").concat(character + 1, "\n").concat(message));
|
|
401
421
|
} else {
|
|
402
422
|
console.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
|
|
403
423
|
}
|
|
404
424
|
});
|
|
425
|
+
|
|
405
426
|
if (emitResult.emitSkipped) {
|
|
406
|
-
const errors = allDiagnostics.filter(
|
|
427
|
+
const errors = allDiagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Error);
|
|
428
|
+
|
|
407
429
|
if (errors.length) {
|
|
408
430
|
console.error(ts.formatDiagnostics(errors, formatHost));
|
|
409
431
|
throw new Error("failed to compile");
|
|
410
432
|
}
|
|
411
433
|
}
|
|
412
|
-
const typesPath = path.resolve(outDir, path.relative(rootDir, path.resolve(cwd, sourcePath))).replace(/\.[jt]sx?$/, ".d.ts");
|
|
413
|
-
return { path: typesPath };
|
|
414
434
|
}
|
|
415
435
|
|
|
416
436
|
class _DtsError extends Error {
|
|
@@ -418,10 +438,19 @@ class _DtsError extends Error {
|
|
|
418
438
|
super(message);
|
|
419
439
|
this.messages = messages;
|
|
420
440
|
}
|
|
441
|
+
|
|
421
442
|
}
|
|
422
443
|
|
|
423
444
|
function _createApiExtractorConfig(options) {
|
|
424
|
-
const {
|
|
445
|
+
const {
|
|
446
|
+
distPath,
|
|
447
|
+
exportPath,
|
|
448
|
+
filePath,
|
|
449
|
+
messages,
|
|
450
|
+
projectPath,
|
|
451
|
+
sourcePath,
|
|
452
|
+
tsconfigPath
|
|
453
|
+
} = options;
|
|
425
454
|
return {
|
|
426
455
|
apiReport: {
|
|
427
456
|
enabled: false,
|
|
@@ -432,7 +461,7 @@ function _createApiExtractorConfig(options) {
|
|
|
432
461
|
},
|
|
433
462
|
docModel: {
|
|
434
463
|
enabled: false,
|
|
435
|
-
apiJsonFilePath: path.resolve(distPath,
|
|
464
|
+
apiJsonFilePath: path.resolve(distPath, "".concat(exportPath, ".api.json"))
|
|
436
465
|
},
|
|
437
466
|
dtsRollup: {
|
|
438
467
|
enabled: true,
|
|
@@ -448,31 +477,33 @@ function _createApiExtractorConfig(options) {
|
|
|
448
477
|
}
|
|
449
478
|
|
|
450
479
|
async function _createTSDocConfig(opts) {
|
|
451
|
-
const {
|
|
480
|
+
const {
|
|
481
|
+
customTags
|
|
482
|
+
} = opts;
|
|
483
|
+
|
|
452
484
|
if (customTags.length === 0) {
|
|
453
485
|
return void 0;
|
|
454
486
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
);
|
|
487
|
+
|
|
488
|
+
const tsDocBaseBuf = await readFile(require.resolve("@microsoft/api-extractor/extends/tsdoc-base.json"));
|
|
458
489
|
const tsDocBaseConfig = parse(tsDocBaseBuf.toString());
|
|
459
|
-
const tagDefinitions = (tsDocBaseConfig.tagDefinitions || []).concat(
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
);
|
|
466
|
-
|
|
490
|
+
const tagDefinitions = (tsDocBaseConfig.tagDefinitions || []).concat(customTags.map(t => ({
|
|
491
|
+
tagName: "@".concat(t.name),
|
|
492
|
+
syntaxKind: t.syntaxKind,
|
|
493
|
+
allowMultiple: t.allowMultiple
|
|
494
|
+
})));
|
|
495
|
+
|
|
496
|
+
const supportForTags = _objectSpread({}, tsDocBaseConfig.supportForTags);
|
|
497
|
+
|
|
467
498
|
for (const customTag of customTags) {
|
|
468
|
-
supportForTags[
|
|
499
|
+
supportForTags["@".concat(customTag.name)] = true;
|
|
469
500
|
}
|
|
470
|
-
|
|
471
|
-
|
|
501
|
+
|
|
502
|
+
return TSDocConfigFile.loadFromObject(_objectSpread(_objectSpread({}, tsDocBaseConfig), {}, {
|
|
472
503
|
noStandardTags: false,
|
|
473
504
|
tagDefinitions,
|
|
474
505
|
supportForTags
|
|
475
|
-
});
|
|
506
|
+
}));
|
|
476
507
|
}
|
|
477
508
|
|
|
478
509
|
const _LOG_LEVELS = {
|
|
@@ -481,15 +512,27 @@ const _LOG_LEVELS = {
|
|
|
481
512
|
off: "none",
|
|
482
513
|
warn: "warning"
|
|
483
514
|
};
|
|
515
|
+
|
|
484
516
|
async function _extractTypes(options) {
|
|
485
|
-
const {
|
|
517
|
+
const {
|
|
518
|
+
distPath,
|
|
519
|
+
exportPath,
|
|
520
|
+
files,
|
|
521
|
+
filePath,
|
|
522
|
+
projectPath,
|
|
523
|
+
rules,
|
|
524
|
+
sourcePath,
|
|
525
|
+
tsconfigPath
|
|
526
|
+
} = options;
|
|
486
527
|
const tsdocConfigFile = await _createTSDocConfig({
|
|
487
528
|
customTags: []
|
|
488
529
|
});
|
|
530
|
+
|
|
489
531
|
function _ruleToLogLevel(key, defaultLevel) {
|
|
490
532
|
const r = rules == null ? void 0 : rules[key];
|
|
491
533
|
return r ? _LOG_LEVELS[r] : defaultLevel || "warning";
|
|
492
534
|
}
|
|
535
|
+
|
|
493
536
|
const messagesConfig = {
|
|
494
537
|
compilerMessageReporting: {
|
|
495
538
|
default: {
|
|
@@ -547,79 +590,91 @@ async function _extractTypes(options) {
|
|
|
547
590
|
const extractorResult = Extractor.invoke(extractorConfig, {
|
|
548
591
|
localBuild: true,
|
|
549
592
|
showVerboseMessages: true,
|
|
593
|
+
|
|
550
594
|
messageCallback(message) {
|
|
551
595
|
messages.push(message);
|
|
552
596
|
message.handled = true;
|
|
553
597
|
}
|
|
598
|
+
|
|
554
599
|
});
|
|
555
600
|
const typesPath = path.resolve(distPath, filePath);
|
|
556
601
|
const typesBuf = await fs.readFile(typesPath);
|
|
557
602
|
const prettierConfig = await prettier.resolveConfig(typesPath);
|
|
558
603
|
await mkdirp(path.dirname(typesPath));
|
|
559
|
-
await fs.writeFile(
|
|
560
|
-
typesPath
|
|
561
|
-
|
|
562
|
-
...prettierConfig,
|
|
563
|
-
filepath: typesPath
|
|
564
|
-
})
|
|
565
|
-
);
|
|
604
|
+
await fs.writeFile(typesPath, prettier.format(typesBuf.toString(), _objectSpread(_objectSpread({}, prettierConfig), {}, {
|
|
605
|
+
filepath: typesPath
|
|
606
|
+
})));
|
|
566
607
|
files.push({
|
|
567
608
|
type: "types",
|
|
568
609
|
path: typesPath
|
|
569
610
|
});
|
|
570
|
-
return {
|
|
611
|
+
return {
|
|
612
|
+
extractorResult,
|
|
613
|
+
messages
|
|
614
|
+
};
|
|
571
615
|
}
|
|
572
616
|
|
|
573
|
-
const rimraf = promisify(rimrafCallback);
|
|
574
617
|
async function _doExtract(ctx, task) {
|
|
575
618
|
var _a;
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
619
|
+
|
|
620
|
+
const {
|
|
621
|
+
config,
|
|
622
|
+
cwd,
|
|
623
|
+
dist,
|
|
624
|
+
files,
|
|
625
|
+
ts
|
|
626
|
+
} = ctx;
|
|
627
|
+
if (!ts.config || !ts.configPath) return {
|
|
628
|
+
type: "dts",
|
|
629
|
+
messages: []
|
|
587
630
|
};
|
|
588
|
-
const
|
|
631
|
+
const distPath = path.resolve(cwd, dist);
|
|
632
|
+
const {
|
|
633
|
+
outDir = distPath,
|
|
634
|
+
rootDir = cwd
|
|
635
|
+
} = ts.config.options;
|
|
636
|
+
await _buildTypes({
|
|
589
637
|
cwd,
|
|
590
|
-
outDir
|
|
591
|
-
sourcePath,
|
|
638
|
+
outDir,
|
|
592
639
|
tsconfig: ts.config
|
|
593
640
|
});
|
|
594
|
-
const
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
filePath,
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
641
|
+
const messages = [];
|
|
642
|
+
|
|
643
|
+
for (const entry of task.entries) {
|
|
644
|
+
const exportPath = entry.exportPath === "." ? "./index" : entry.exportPath;
|
|
645
|
+
const filePath = path.relative(distPath, path.resolve(cwd, entry.targetPath));
|
|
646
|
+
const result = await _extractTypes({
|
|
647
|
+
cwd,
|
|
648
|
+
exportPath,
|
|
649
|
+
files,
|
|
650
|
+
filePath,
|
|
651
|
+
projectPath: cwd,
|
|
652
|
+
rules: (_a = config == null ? void 0 : config.extract) == null ? void 0 : _a.rules,
|
|
653
|
+
sourcePath: path.resolve(outDir, path.relative(cwd, rootDir), entry.sourcePath.replace(/\.ts$/, ".d.ts")),
|
|
654
|
+
tsconfigPath: path.resolve(cwd, ts.configPath),
|
|
655
|
+
distPath
|
|
656
|
+
});
|
|
657
|
+
messages.push(...result.messages);
|
|
658
|
+
|
|
659
|
+
if (result.messages.some(msg => msg.logLevel === "error")) {
|
|
660
|
+
throw new _DtsError("encountered errors when extracting types", result.messages);
|
|
661
|
+
}
|
|
608
662
|
}
|
|
609
|
-
|
|
663
|
+
|
|
664
|
+
return {
|
|
665
|
+
type: "dts",
|
|
666
|
+
messages
|
|
667
|
+
};
|
|
610
668
|
}
|
|
611
669
|
|
|
612
670
|
const _dtsTask = {
|
|
613
|
-
name: (_ctx, task) => [
|
|
614
|
-
`build type definitions`,
|
|
615
|
-
` ${chalk.blue(task.importId)}: ${task.sourcePath} -> ${task.targetPath}`
|
|
616
|
-
].join("\n"),
|
|
671
|
+
name: (_ctx, task) => ["build type definitions", ...task.entries.map(entry => " ".concat(chalk.blue(entry.importId), ": ").concat(entry.sourcePath, " -> ").concat(entry.targetPath))].join("\n"),
|
|
617
672
|
exec: (ctx, task) => {
|
|
618
|
-
return new Observable(
|
|
619
|
-
_doExtract(ctx, task).then(
|
|
673
|
+
return new Observable(observer => {
|
|
674
|
+
_doExtract(ctx, task).then(result => {
|
|
620
675
|
observer.next(result);
|
|
621
676
|
observer.complete();
|
|
622
|
-
}).catch(
|
|
677
|
+
}).catch(err => {
|
|
623
678
|
observer.error(err);
|
|
624
679
|
});
|
|
625
680
|
});
|
|
@@ -628,7 +683,10 @@ const _dtsTask = {
|
|
|
628
683
|
_printExtractMessages(ctx, result.messages);
|
|
629
684
|
},
|
|
630
685
|
error: (ctx, _task, err) => {
|
|
631
|
-
const {
|
|
686
|
+
const {
|
|
687
|
+
logger
|
|
688
|
+
} = ctx;
|
|
689
|
+
|
|
632
690
|
if (err instanceof _DtsError) {
|
|
633
691
|
_printExtractMessages(ctx, err.messages);
|
|
634
692
|
} else if (err instanceof Error) {
|
|
@@ -636,28 +694,31 @@ const _dtsTask = {
|
|
|
636
694
|
}
|
|
637
695
|
}
|
|
638
696
|
};
|
|
639
|
-
|
|
640
697
|
const _dtsWatchTask = {
|
|
641
|
-
name: (_ctx, task) => [
|
|
642
|
-
`build type definitions`,
|
|
643
|
-
` ${chalk.blue(task.importId)}: ${task.sourcePath} -> ${task.targetPath}`
|
|
644
|
-
].join("\n"),
|
|
698
|
+
name: (_ctx, task) => ["build type definitions", ...task.entries.map(entry => " ".concat(chalk.blue(entry.importId), ": ").concat(entry.sourcePath, " -> ").concat(entry.targetPath))].join("\n"),
|
|
645
699
|
exec: (ctx, task) => {
|
|
646
|
-
return new Observable(
|
|
647
|
-
_doExtract(ctx, task).then(
|
|
700
|
+
return new Observable(observer => {
|
|
701
|
+
_doExtract(ctx, task).then(result => {
|
|
648
702
|
observer.next(result);
|
|
649
703
|
observer.complete();
|
|
650
|
-
}).catch(
|
|
704
|
+
}).catch(err => observer.error(err));
|
|
651
705
|
});
|
|
652
706
|
},
|
|
653
707
|
complete: (ctx, _task, result) => {
|
|
654
|
-
const {
|
|
708
|
+
const {
|
|
709
|
+
logger
|
|
710
|
+
} = ctx;
|
|
711
|
+
|
|
655
712
|
_printExtractMessages(ctx, result.messages);
|
|
713
|
+
|
|
656
714
|
logger.warn("watching typescript definitions is currently not supported");
|
|
657
715
|
logger.log();
|
|
658
716
|
},
|
|
659
717
|
error: (ctx, _task, err) => {
|
|
660
|
-
const {
|
|
718
|
+
const {
|
|
719
|
+
logger
|
|
720
|
+
} = ctx;
|
|
721
|
+
|
|
661
722
|
if (err instanceof _DtsError) {
|
|
662
723
|
_printExtractMessages(ctx, err.messages);
|
|
663
724
|
} else if (err instanceof Error) {
|
|
@@ -667,124 +728,184 @@ const _dtsWatchTask = {
|
|
|
667
728
|
};
|
|
668
729
|
|
|
669
730
|
function _resolveRollupConfig(ctx, buildTask) {
|
|
670
|
-
var
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
const
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
731
|
+
var _ref2, _ref4, _ref5, _ref6, _ref7, _ref8;
|
|
732
|
+
|
|
733
|
+
var _a;
|
|
734
|
+
|
|
735
|
+
const {
|
|
736
|
+
format,
|
|
737
|
+
runtime,
|
|
738
|
+
target
|
|
739
|
+
} = buildTask;
|
|
740
|
+
const {
|
|
741
|
+
config,
|
|
742
|
+
cwd,
|
|
743
|
+
exports: _exports,
|
|
744
|
+
external,
|
|
745
|
+
dist: outDir,
|
|
746
|
+
logger,
|
|
747
|
+
pkg,
|
|
748
|
+
ts
|
|
749
|
+
} = ctx;
|
|
750
|
+
const outputExt = format === "commonjs" ? ".cjs" : ".js";
|
|
751
|
+
const minify = (_ref2 = config == null ? void 0 : config.minify) !== null && _ref2 !== void 0 ? _ref2 : true;
|
|
752
|
+
const pathAliases = Object.fromEntries(Object.entries(((_a = ts.config) == null ? void 0 : _a.options.paths) || {}).map(_ref3 => {
|
|
753
|
+
let [key, val] = _ref3;
|
|
754
|
+
|
|
755
|
+
var _a2;
|
|
756
|
+
|
|
757
|
+
return [key, path.resolve(cwd, ((_a2 = ts.config) == null ? void 0 : _a2.options.baseUrl) || ".", val[0])];
|
|
758
|
+
}));
|
|
759
|
+
const entries = buildTask.entries.map(entry => {
|
|
760
|
+
return _objectSpread(_objectSpread({}, entry), {}, {
|
|
683
761
|
name: path.relative(outDir, entry.output).replace(/\.[^/.]+$/, "")
|
|
684
|
-
};
|
|
762
|
+
});
|
|
685
763
|
}, {});
|
|
764
|
+
|
|
765
|
+
const exportIds = _exports && Object.keys(_exports).map(exportPath => path.join(pkg.name, exportPath));
|
|
766
|
+
|
|
767
|
+
const sourcePaths = _exports && Object.values(_exports).map(e => path.resolve(cwd, e.source));
|
|
768
|
+
|
|
686
769
|
return {
|
|
687
770
|
inputOptions: {
|
|
688
771
|
context: cwd,
|
|
689
|
-
external: (id) => {
|
|
772
|
+
external: (id, importer) => {
|
|
773
|
+
if (exportIds == null ? void 0 : exportIds.includes(id)) {
|
|
774
|
+
return true;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
if (importer && (id.startsWith(".") || id.startsWith("/"))) {
|
|
778
|
+
const idPath = path.resolve(path.dirname(importer), id);
|
|
779
|
+
|
|
780
|
+
if (sourcePaths == null ? void 0 : sourcePaths.includes(idPath)) {
|
|
781
|
+
logger.warn("detected self-referencing import \u2013 treating as external: ".concat(path.relative(cwd, idPath)));
|
|
782
|
+
return true;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
|
|
690
786
|
const idParts = id.split("/");
|
|
691
|
-
const name = idParts[0].startsWith("@") ?
|
|
787
|
+
const name = idParts[0].startsWith("@") ? "".concat(idParts[0], "/").concat(idParts[1]) : idParts[0];
|
|
788
|
+
|
|
692
789
|
if (name && external.includes(name)) {
|
|
693
790
|
return true;
|
|
694
791
|
}
|
|
792
|
+
|
|
695
793
|
return false;
|
|
696
794
|
},
|
|
697
795
|
input: entries.reduce((acc, entry) => {
|
|
698
|
-
return {
|
|
796
|
+
return _objectSpread(_objectSpread({}, acc), {}, {
|
|
797
|
+
[entry.name]: entry.source
|
|
798
|
+
});
|
|
699
799
|
}, {}),
|
|
800
|
+
|
|
700
801
|
onwarn(warning, rollupWarn) {
|
|
701
802
|
if (!warning.code || !["CIRCULAR_DEPENDENCY"].includes(warning.code)) {
|
|
702
803
|
rollupWarn(warning);
|
|
703
804
|
}
|
|
704
805
|
},
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
}
|
|
716
|
-
return JSON.stringify(
|
|
717
|
-
path.relative(cwd, path.resolve(outDir, entry.name + outputExt))
|
|
718
|
-
);
|
|
719
|
-
},
|
|
720
|
-
"process.env.PKG_FORMAT": JSON.stringify(format),
|
|
721
|
-
"process.env.PKG_RUNTIME": JSON.stringify(runtime),
|
|
722
|
-
"process.env.PKG_VERSION": JSON.stringify(process.env.PKG_VERSION || pkg.version)
|
|
806
|
+
|
|
807
|
+
plugins: [replace({
|
|
808
|
+
preventAssignment: true,
|
|
809
|
+
values: _objectSpread({}, pkg.name === "@sanity/pkg-utils" ? {} : {
|
|
810
|
+
"process.env.PKG_FILE_PATH": arg => {
|
|
811
|
+
const sourcePath = "./" + path.relative(cwd, arg);
|
|
812
|
+
const entry = entries.find(e => e.source === sourcePath);
|
|
813
|
+
|
|
814
|
+
if (!entry) {
|
|
815
|
+
throw new Error("could not find source entry: ".concat(sourcePath));
|
|
723
816
|
}
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
browser: runtime === "browser",
|
|
731
|
-
extensions: [".cjs", ".mjs", ".js", ".jsx", ".json", ".node"],
|
|
732
|
-
preferBuiltins: true
|
|
733
|
-
}),
|
|
734
|
-
commonjs({
|
|
735
|
-
esmExternals: false,
|
|
736
|
-
extensions: [".js"]
|
|
737
|
-
}),
|
|
738
|
-
json(),
|
|
739
|
-
esbuild({
|
|
740
|
-
minify: (_b = config == null ? void 0 : config.minify) != null ? _b : true,
|
|
741
|
-
jsx: (_c = config == null ? void 0 : config.jsx) != null ? _c : "automatic",
|
|
742
|
-
jsxFactory: (_d = config == null ? void 0 : config.jsxFactory) != null ? _d : "createElement",
|
|
743
|
-
jsxFragment: (_e = config == null ? void 0 : config.jsxFragment) != null ? _e : "Fragment",
|
|
744
|
-
jsxImportSource: (_f = config == null ? void 0 : config.jsxImportSource) != null ? _f : "react",
|
|
745
|
-
target,
|
|
746
|
-
tsconfig: ctx.ts.configPath || "tsconfig.json"
|
|
817
|
+
|
|
818
|
+
return JSON.stringify(path.relative(cwd, path.resolve(outDir, entry.name + outputExt)));
|
|
819
|
+
},
|
|
820
|
+
"process.env.PKG_FORMAT": JSON.stringify(format),
|
|
821
|
+
"process.env.PKG_RUNTIME": JSON.stringify(runtime),
|
|
822
|
+
"process.env.PKG_VERSION": JSON.stringify(process.env.PKG_VERSION || pkg.version)
|
|
747
823
|
})
|
|
748
|
-
|
|
824
|
+
}), alias({
|
|
825
|
+
entries: _objectSpread({}, pathAliases)
|
|
826
|
+
}), nodeResolve({
|
|
827
|
+
browser: runtime === "browser",
|
|
828
|
+
extensions: [".cjs", ".mjs", ".js", ".jsx", ".json", ".node"],
|
|
829
|
+
preferBuiltins: true
|
|
830
|
+
}), commonjs({
|
|
831
|
+
esmExternals: false,
|
|
832
|
+
extensions: [".js"]
|
|
833
|
+
}), json(), esbuild({
|
|
834
|
+
jsx: (_ref4 = config == null ? void 0 : config.jsx) !== null && _ref4 !== void 0 ? _ref4 : "automatic",
|
|
835
|
+
jsxFactory: (_ref5 = config == null ? void 0 : config.jsxFactory) !== null && _ref5 !== void 0 ? _ref5 : "createElement",
|
|
836
|
+
jsxFragment: (_ref6 = config == null ? void 0 : config.jsxFragment) !== null && _ref6 !== void 0 ? _ref6 : "Fragment",
|
|
837
|
+
jsxImportSource: (_ref7 = config == null ? void 0 : config.jsxImportSource) !== null && _ref7 !== void 0 ? _ref7 : "react",
|
|
838
|
+
target,
|
|
839
|
+
tsconfig: ctx.ts.configPath || "tsconfig.json"
|
|
840
|
+
}), getBabelOutputPlugin({
|
|
841
|
+
babelrc: false,
|
|
842
|
+
plugins: ["@babel/plugin-proposal-object-rest-spread"],
|
|
843
|
+
presets: [["@babel/preset-env", {
|
|
844
|
+
targets: pkg.browserslist || _DEFAULTS.browserslist
|
|
845
|
+
}]]
|
|
846
|
+
}), minify && terser({
|
|
847
|
+
output: {
|
|
848
|
+
comments: (_node, comment) => {
|
|
849
|
+
const text = comment.value;
|
|
850
|
+
const type = comment.type;
|
|
851
|
+
|
|
852
|
+
if (type == "comment2") {
|
|
853
|
+
return /@preserve|@license|@cc_on/i.test(text);
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
return false;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
})].filter(Boolean),
|
|
749
860
|
treeshake: {
|
|
750
861
|
propertyReadSideEffects: false
|
|
751
862
|
}
|
|
752
863
|
},
|
|
753
864
|
outputOptions: {
|
|
754
|
-
chunkFileNames: () =>
|
|
865
|
+
chunkFileNames: () => "_[name]-[hash]".concat(outputExt),
|
|
755
866
|
dir: outDir,
|
|
756
|
-
entryFileNames: () =>
|
|
867
|
+
entryFileNames: () => "[name]".concat(outputExt),
|
|
757
868
|
format,
|
|
758
869
|
exports: "auto",
|
|
759
|
-
sourcemap: (
|
|
870
|
+
sourcemap: (_ref8 = config == null ? void 0 : config.sourcemap) !== null && _ref8 !== void 0 ? _ref8 : true
|
|
760
871
|
}
|
|
761
872
|
};
|
|
762
873
|
}
|
|
763
874
|
|
|
764
875
|
const _rollupTask = {
|
|
765
|
-
name: (ctx, task) =>
|
|
766
|
-
${task.entries.map((e) => `${chalk.blue(path.join(ctx.pkg.name, e.path))}: ${e.source} -> ${e.output}`).join("\n ")}`,
|
|
876
|
+
name: (ctx, task) => "build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path.join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")),
|
|
767
877
|
exec: (ctx, task) => {
|
|
768
|
-
return new Observable(
|
|
769
|
-
_execPromise(ctx, task).then(
|
|
878
|
+
return new Observable(observer => {
|
|
879
|
+
_execPromise(ctx, task).then(result => {
|
|
770
880
|
observer.next(result);
|
|
771
881
|
observer.complete();
|
|
772
|
-
}).catch(
|
|
882
|
+
}).catch(err => observer.error(err));
|
|
773
883
|
});
|
|
774
884
|
},
|
|
775
|
-
complete: () => {
|
|
776
|
-
},
|
|
885
|
+
complete: () => {},
|
|
777
886
|
error: (_ctx, _task, err) => {
|
|
778
887
|
if (err instanceof Error) {
|
|
779
888
|
console.log(err);
|
|
780
889
|
}
|
|
781
890
|
}
|
|
782
891
|
};
|
|
892
|
+
|
|
783
893
|
async function _execPromise(ctx, task) {
|
|
784
|
-
const {
|
|
785
|
-
|
|
894
|
+
const {
|
|
895
|
+
files,
|
|
896
|
+
dist: outDir
|
|
897
|
+
} = ctx;
|
|
898
|
+
|
|
899
|
+
const {
|
|
900
|
+
inputOptions,
|
|
901
|
+
outputOptions
|
|
902
|
+
} = _resolveRollupConfig(ctx, task);
|
|
903
|
+
|
|
786
904
|
const bundle = await rollup(inputOptions);
|
|
787
|
-
const {
|
|
905
|
+
const {
|
|
906
|
+
output
|
|
907
|
+
} = await bundle.generate(outputOptions);
|
|
908
|
+
|
|
788
909
|
for (const chunkOrAsset of output) {
|
|
789
910
|
if (chunkOrAsset.type === "asset") {
|
|
790
911
|
files.push({
|
|
@@ -798,22 +919,26 @@ async function _execPromise(ctx, task) {
|
|
|
798
919
|
});
|
|
799
920
|
}
|
|
800
921
|
}
|
|
922
|
+
|
|
801
923
|
await bundle.write(outputOptions);
|
|
802
924
|
await bundle.close();
|
|
803
925
|
}
|
|
804
926
|
|
|
805
927
|
const _rollupWatchTask = {
|
|
806
|
-
name: (ctx, task) =>
|
|
807
|
-
${task.entries.map((e) => `${chalk.blue(path.join(ctx.pkg.name, e.path))}: ${e.source} -> ${e.output}`).join("\n ")}`,
|
|
928
|
+
name: (ctx, task) => "build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path.join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")),
|
|
808
929
|
exec: (ctx, task) => {
|
|
809
|
-
const {
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
930
|
+
const {
|
|
931
|
+
inputOptions,
|
|
932
|
+
outputOptions
|
|
933
|
+
} = _resolveRollupConfig(ctx, task);
|
|
934
|
+
|
|
935
|
+
return new Observable(observer => {
|
|
936
|
+
const watchOptions = _objectSpread(_objectSpread({}, inputOptions), {}, {
|
|
813
937
|
output: outputOptions
|
|
814
|
-
};
|
|
938
|
+
});
|
|
939
|
+
|
|
815
940
|
const watcher = watch$1(watchOptions);
|
|
816
|
-
watcher.on("event",
|
|
941
|
+
watcher.on("event", event => {
|
|
817
942
|
observer.next(event);
|
|
818
943
|
});
|
|
819
944
|
return () => {
|
|
@@ -822,37 +947,43 @@ const _rollupWatchTask = {
|
|
|
822
947
|
});
|
|
823
948
|
},
|
|
824
949
|
complete: (ctx, task, event) => {
|
|
825
|
-
const {
|
|
950
|
+
const {
|
|
951
|
+
logger
|
|
952
|
+
} = ctx;
|
|
953
|
+
|
|
826
954
|
if (event.code === "BUNDLE_END") {
|
|
827
|
-
logger.success(
|
|
828
|
-
`build javascript files (target ${task.target.join(" + ")}, format ${task.format})
|
|
829
|
-
${task.entries.map((e) => `${chalk.blue(path.join(ctx.pkg.name, e.path))}: ${e.source} -> ${e.output}`).join("\n ")}`
|
|
830
|
-
);
|
|
955
|
+
logger.success("build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path.join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")));
|
|
831
956
|
logger.log("");
|
|
832
957
|
return;
|
|
833
958
|
}
|
|
959
|
+
|
|
834
960
|
if (event.code === "BUNDLE_START") {
|
|
835
961
|
return;
|
|
836
962
|
}
|
|
963
|
+
|
|
837
964
|
if (event.code === "END") {
|
|
838
965
|
return;
|
|
839
966
|
}
|
|
967
|
+
|
|
840
968
|
if (event.code === "ERROR") {
|
|
841
969
|
logger.error(event.code, event);
|
|
842
970
|
return;
|
|
843
971
|
}
|
|
972
|
+
|
|
844
973
|
if (event.code === "START") {
|
|
845
974
|
return;
|
|
846
975
|
}
|
|
847
976
|
},
|
|
848
977
|
error: (ctx, _task, err) => {
|
|
849
|
-
const {
|
|
978
|
+
const {
|
|
979
|
+
logger
|
|
980
|
+
} = ctx;
|
|
981
|
+
|
|
850
982
|
if (err instanceof Error) {
|
|
851
983
|
logger.log(err);
|
|
852
984
|
}
|
|
853
985
|
}
|
|
854
986
|
};
|
|
855
|
-
|
|
856
987
|
const _buildTaskHandlers = {
|
|
857
988
|
"build:dts": _dtsTask,
|
|
858
989
|
"build:js": _rollupTask
|
|
@@ -867,29 +998,33 @@ function _sortAsNumber(a, b) {
|
|
|
867
998
|
const bVersion = Number(b);
|
|
868
999
|
return aVersion - bVersion;
|
|
869
1000
|
}
|
|
1001
|
+
|
|
870
1002
|
function _resolveBrowserslistVersions(query) {
|
|
871
1003
|
const result = browserslist(query);
|
|
872
|
-
const entries = result.map(
|
|
1004
|
+
const entries = result.map(key => {
|
|
873
1005
|
const [name, version] = key.split(" ");
|
|
874
|
-
return {
|
|
1006
|
+
return {
|
|
1007
|
+
name,
|
|
1008
|
+
version: version.split("-")[0].split(".")[0]
|
|
1009
|
+
};
|
|
875
1010
|
});
|
|
876
|
-
const andChr = entries.filter(
|
|
877
|
-
const andFf = entries.filter(
|
|
878
|
-
const chrome = entries.filter(
|
|
879
|
-
const edge = entries.filter(
|
|
880
|
-
const ff = entries.filter(
|
|
881
|
-
const iosSaf = entries.filter(
|
|
882
|
-
const saf = entries.filter(
|
|
883
|
-
const opera = entries.filter(
|
|
884
|
-
const node = entries.filter(
|
|
1011
|
+
const andChr = entries.filter(b => b.name === "and_chr");
|
|
1012
|
+
const andFf = entries.filter(b => b.name === "and_ff");
|
|
1013
|
+
const chrome = entries.filter(b => b.name === "chrome");
|
|
1014
|
+
const edge = entries.filter(b => b.name === "edge");
|
|
1015
|
+
const ff = entries.filter(b => b.name === "firefox");
|
|
1016
|
+
const iosSaf = entries.filter(b => b.name === "ios_saf");
|
|
1017
|
+
const saf = entries.filter(b => b.name === "safari");
|
|
1018
|
+
const opera = entries.filter(b => b.name === "opera");
|
|
1019
|
+
const node = entries.filter(b => b.name === "node");
|
|
885
1020
|
const versions = {
|
|
886
|
-
chrome: andChr.concat(chrome).map(
|
|
887
|
-
ff: andFf.concat(ff).map(
|
|
888
|
-
edge: edge.map(
|
|
889
|
-
iosSaf: iosSaf.map(
|
|
890
|
-
saf: saf.map(
|
|
891
|
-
opera: opera.map(
|
|
892
|
-
node: node.map(
|
|
1021
|
+
chrome: andChr.concat(chrome).map(b => b.version),
|
|
1022
|
+
ff: andFf.concat(ff).map(b => b.version),
|
|
1023
|
+
edge: edge.map(b => b.version),
|
|
1024
|
+
iosSaf: iosSaf.map(b => b.version),
|
|
1025
|
+
saf: saf.map(b => b.version),
|
|
1026
|
+
opera: opera.map(b => b.version),
|
|
1027
|
+
node: node.map(b => b.version)
|
|
893
1028
|
};
|
|
894
1029
|
versions.chrome.sort(_sortAsNumber);
|
|
895
1030
|
versions.ff.sort(_sortAsNumber);
|
|
@@ -903,71 +1038,108 @@ function _resolveBrowserslistVersions(query) {
|
|
|
903
1038
|
|
|
904
1039
|
function _resolveBrowserTarget(versions) {
|
|
905
1040
|
const target = [];
|
|
1041
|
+
|
|
906
1042
|
if (versions.chrome.length) {
|
|
907
|
-
target.push(
|
|
1043
|
+
target.push("chrome".concat(versions.chrome[0]));
|
|
908
1044
|
}
|
|
1045
|
+
|
|
909
1046
|
if (versions.ff.length) {
|
|
910
|
-
target.push(
|
|
1047
|
+
target.push("firefox".concat(versions.ff[0]));
|
|
911
1048
|
}
|
|
1049
|
+
|
|
912
1050
|
if (versions.edge.length) {
|
|
913
|
-
target.push(
|
|
1051
|
+
target.push("edge".concat(versions.edge[0]));
|
|
914
1052
|
}
|
|
1053
|
+
|
|
915
1054
|
if (versions.iosSaf.length) {
|
|
916
|
-
target.push(
|
|
1055
|
+
target.push("ios".concat(versions.iosSaf[0]));
|
|
917
1056
|
}
|
|
1057
|
+
|
|
918
1058
|
if (versions.saf.length) {
|
|
919
|
-
target.push(
|
|
1059
|
+
target.push("safari".concat(versions.saf[0]));
|
|
920
1060
|
}
|
|
1061
|
+
|
|
921
1062
|
if (versions.opera.length) {
|
|
922
|
-
target.push(
|
|
1063
|
+
target.push("opera".concat(versions.opera[0]));
|
|
923
1064
|
}
|
|
1065
|
+
|
|
924
1066
|
if (target.length === 0) {
|
|
925
1067
|
return void 0;
|
|
926
1068
|
}
|
|
1069
|
+
|
|
927
1070
|
return target;
|
|
928
1071
|
}
|
|
929
1072
|
|
|
930
1073
|
function _resolveNodeTarget(versions) {
|
|
931
1074
|
const target = [];
|
|
1075
|
+
|
|
932
1076
|
if (versions.node.length) {
|
|
933
|
-
target.push(
|
|
1077
|
+
target.push("node".concat(versions.node[0]));
|
|
934
1078
|
}
|
|
1079
|
+
|
|
935
1080
|
if (target.length === 0) {
|
|
936
1081
|
return void 0;
|
|
937
1082
|
}
|
|
1083
|
+
|
|
938
1084
|
return target;
|
|
939
1085
|
}
|
|
940
1086
|
|
|
941
1087
|
async function _resolveBuildContext(options) {
|
|
942
|
-
var
|
|
943
|
-
|
|
944
|
-
const
|
|
1088
|
+
var _ref9;
|
|
1089
|
+
|
|
1090
|
+
const {
|
|
1091
|
+
config,
|
|
1092
|
+
cwd,
|
|
1093
|
+
pkg,
|
|
1094
|
+
tsconfig: tsconfigPath
|
|
1095
|
+
} = options;
|
|
1096
|
+
const tsconfig = await _loadTSConfig({
|
|
1097
|
+
cwd,
|
|
1098
|
+
tsconfigPath
|
|
1099
|
+
});
|
|
1100
|
+
|
|
945
1101
|
const targetVersions = _resolveBrowserslistVersions(pkg.browserslist || _DEFAULTS.browserslist);
|
|
1102
|
+
|
|
946
1103
|
const srcPath = path.resolve(cwd, (config == null ? void 0 : config.src) || "src");
|
|
947
1104
|
const distPath = path.resolve(cwd, (config == null ? void 0 : config.dist) || "dist");
|
|
1105
|
+
|
|
948
1106
|
const nodeTarget = _resolveNodeTarget(targetVersions);
|
|
1107
|
+
|
|
949
1108
|
const webTarget = _resolveBrowserTarget(targetVersions);
|
|
1109
|
+
|
|
950
1110
|
if (!nodeTarget) {
|
|
951
1111
|
throw new Error("no matching `node` target");
|
|
952
1112
|
}
|
|
1113
|
+
|
|
953
1114
|
if (!webTarget) {
|
|
954
1115
|
throw new Error("no matching `web` target");
|
|
955
1116
|
}
|
|
1117
|
+
|
|
956
1118
|
const target = {
|
|
957
1119
|
"*": webTarget.concat(nodeTarget),
|
|
958
1120
|
browser: webTarget,
|
|
959
1121
|
node: nodeTarget
|
|
960
1122
|
};
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
1123
|
+
|
|
1124
|
+
const parsedExports = _parseExports({
|
|
1125
|
+
pkg
|
|
1126
|
+
}).reduce((acc, x) => {
|
|
1127
|
+
const {
|
|
1128
|
+
_path: exportPath
|
|
1129
|
+
} = x,
|
|
1130
|
+
exportEntry = _objectWithoutProperties(x, _excluded);
|
|
1131
|
+
|
|
1132
|
+
return _objectSpread(_objectSpread({}, acc), {}, {
|
|
1133
|
+
[exportPath]: exportEntry
|
|
1134
|
+
});
|
|
964
1135
|
}, {});
|
|
1136
|
+
|
|
965
1137
|
const exports = _resolveConfigProperty(config == null ? void 0 : config.exports, parsedExports);
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
];
|
|
1138
|
+
|
|
1139
|
+
const parsedExternal = [...(pkg.dependencies ? Object.keys(pkg.dependencies) : []), ...(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [])];
|
|
1140
|
+
|
|
970
1141
|
const external = _resolveConfigProperty(config == null ? void 0 : config.external, parsedExternal);
|
|
1142
|
+
|
|
971
1143
|
const ctx = {
|
|
972
1144
|
config,
|
|
973
1145
|
cwd,
|
|
@@ -976,25 +1148,41 @@ async function _resolveBuildContext(options) {
|
|
|
976
1148
|
external,
|
|
977
1149
|
files: [],
|
|
978
1150
|
logger: {
|
|
979
|
-
log: (
|
|
980
|
-
console.log(...
|
|
1151
|
+
log: function () {
|
|
1152
|
+
console.log(...arguments);
|
|
981
1153
|
},
|
|
982
|
-
info: (
|
|
1154
|
+
info: function () {
|
|
1155
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1156
|
+
args[_key] = arguments[_key];
|
|
1157
|
+
}
|
|
1158
|
+
|
|
983
1159
|
console.log(chalk.blue(" info"), ...args);
|
|
984
1160
|
},
|
|
985
|
-
warn: (
|
|
1161
|
+
warn: function () {
|
|
1162
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
1163
|
+
args[_key2] = arguments[_key2];
|
|
1164
|
+
}
|
|
1165
|
+
|
|
986
1166
|
console.log(chalk.yellow(" warn"), ...args);
|
|
987
1167
|
},
|
|
988
|
-
error: (
|
|
1168
|
+
error: function () {
|
|
1169
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
1170
|
+
args[_key3] = arguments[_key3];
|
|
1171
|
+
}
|
|
1172
|
+
|
|
989
1173
|
console.log(chalk.red(" fail"), ...args);
|
|
990
1174
|
},
|
|
991
|
-
success: (
|
|
1175
|
+
success: function () {
|
|
1176
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
1177
|
+
args[_key4] = arguments[_key4];
|
|
1178
|
+
}
|
|
1179
|
+
|
|
992
1180
|
console.log(chalk.green(" ok "), ...args);
|
|
993
1181
|
}
|
|
994
1182
|
},
|
|
995
1183
|
pkg,
|
|
996
1184
|
src: path.relative(cwd, srcPath),
|
|
997
|
-
runtime: (
|
|
1185
|
+
runtime: (_ref9 = config == null ? void 0 : config.runtime) !== null && _ref9 !== void 0 ? _ref9 : "*",
|
|
998
1186
|
target,
|
|
999
1187
|
ts: {
|
|
1000
1188
|
config: tsconfig,
|
|
@@ -1006,27 +1194,43 @@ async function _resolveBuildContext(options) {
|
|
|
1006
1194
|
|
|
1007
1195
|
function _spinner(msg) {
|
|
1008
1196
|
const startTime = Date.now();
|
|
1009
|
-
console.log(
|
|
1197
|
+
console.log("".concat(chalk.yellow("run "), " ").concat(msg));
|
|
1010
1198
|
return {
|
|
1011
1199
|
complete: () => {
|
|
1012
|
-
console.log(
|
|
1200
|
+
console.log("".concat(chalk.green("ok "), " ").concat(chalk.gray("".concat(Date.now() - startTime, "ms"))));
|
|
1013
1201
|
},
|
|
1014
1202
|
error: () => {
|
|
1015
|
-
console.log(
|
|
1203
|
+
console.log("".concat(chalk.red("failed"), " ").concat(chalk.gray("".concat(Date.now() - startTime, "ms"))));
|
|
1016
1204
|
}
|
|
1017
1205
|
};
|
|
1018
1206
|
}
|
|
1019
1207
|
|
|
1020
1208
|
async function build(options) {
|
|
1021
|
-
const {
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1209
|
+
const {
|
|
1210
|
+
cwd,
|
|
1211
|
+
tsconfig = "tsconfig.json"
|
|
1212
|
+
} = options;
|
|
1213
|
+
const pkg = await _loadPkgWithReporting({
|
|
1214
|
+
cwd
|
|
1215
|
+
});
|
|
1216
|
+
const config = await _loadConfig({
|
|
1217
|
+
cwd
|
|
1218
|
+
});
|
|
1219
|
+
const ctx = await _resolveBuildContext({
|
|
1220
|
+
config,
|
|
1221
|
+
cwd,
|
|
1222
|
+
pkg,
|
|
1223
|
+
tsconfig
|
|
1224
|
+
});
|
|
1225
|
+
|
|
1025
1226
|
const buildTasks = _resolveBuildTasks(ctx);
|
|
1227
|
+
|
|
1026
1228
|
for (const task of buildTasks) {
|
|
1027
1229
|
const handler = _buildTaskHandlers[task.type];
|
|
1028
1230
|
const taskName = handler.name(ctx, task);
|
|
1231
|
+
|
|
1029
1232
|
const spinner = _spinner(taskName);
|
|
1233
|
+
|
|
1030
1234
|
try {
|
|
1031
1235
|
const result = await handler.exec(ctx, task).toPromise();
|
|
1032
1236
|
spinner.complete();
|
|
@@ -1034,11 +1238,13 @@ async function build(options) {
|
|
|
1034
1238
|
handler.complete(ctx, task, result);
|
|
1035
1239
|
} catch (err) {
|
|
1036
1240
|
spinner.error();
|
|
1241
|
+
|
|
1037
1242
|
if (err instanceof Error) {
|
|
1038
|
-
const RE_CWD = new RegExp(
|
|
1243
|
+
const RE_CWD = new RegExp("".concat(cwd), "g");
|
|
1039
1244
|
ctx.logger.error(err.message.replace(RE_CWD, "."));
|
|
1040
1245
|
ctx.logger.log();
|
|
1041
1246
|
}
|
|
1247
|
+
|
|
1042
1248
|
handler.error(ctx, task, err);
|
|
1043
1249
|
process.exit(1);
|
|
1044
1250
|
}
|
|
@@ -1058,93 +1264,131 @@ function _fileExists(file) {
|
|
|
1058
1264
|
return false;
|
|
1059
1265
|
}
|
|
1060
1266
|
}
|
|
1267
|
+
|
|
1061
1268
|
function _getFileInfo(cwd, filePath) {
|
|
1062
1269
|
const p = path.resolve(cwd, filePath);
|
|
1270
|
+
|
|
1063
1271
|
const exists = _fileExists(p);
|
|
1272
|
+
|
|
1064
1273
|
const size = exists ? _getFilesize(p) : void 0;
|
|
1065
|
-
return {
|
|
1274
|
+
return {
|
|
1275
|
+
exists,
|
|
1276
|
+
size
|
|
1277
|
+
};
|
|
1066
1278
|
}
|
|
1279
|
+
|
|
1067
1280
|
function _printPackageTree(ctx) {
|
|
1068
|
-
const {
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1281
|
+
const {
|
|
1282
|
+
cwd,
|
|
1283
|
+
exports,
|
|
1284
|
+
logger,
|
|
1285
|
+
pkg
|
|
1286
|
+
} = ctx;
|
|
1287
|
+
if (!exports) return;
|
|
1288
|
+
logger.log("".concat(chalk.blue(pkg.name), "@").concat(chalk.green(pkg.version)));
|
|
1072
1289
|
const tree = {};
|
|
1290
|
+
|
|
1073
1291
|
if (pkg.bin) {
|
|
1074
1292
|
tree.bin = pkg.bin;
|
|
1075
1293
|
}
|
|
1294
|
+
|
|
1076
1295
|
function _fileInfo(file) {
|
|
1077
1296
|
const info = _getFileInfo(cwd, file);
|
|
1297
|
+
|
|
1078
1298
|
if (!info.size) {
|
|
1079
|
-
return
|
|
1299
|
+
return "".concat(chalk.gray(file), " ").concat(chalk.red("does not exist"));
|
|
1080
1300
|
}
|
|
1081
|
-
|
|
1301
|
+
|
|
1302
|
+
return "".concat(file, " ").concat(chalk.gray(info.size));
|
|
1082
1303
|
}
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
if (entry.
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1304
|
+
|
|
1305
|
+
tree.exports = Object.fromEntries(Object.entries(exports).filter(_ref10 => {
|
|
1306
|
+
let [, entry] = _ref10;
|
|
1307
|
+
return entry._exported;
|
|
1308
|
+
}).map(_ref11 => {
|
|
1309
|
+
let [exportPath, entry] = _ref11;
|
|
1310
|
+
const exp = {
|
|
1311
|
+
source: entry.source,
|
|
1312
|
+
default: entry.default
|
|
1313
|
+
};
|
|
1314
|
+
|
|
1315
|
+
if (entry.browser) {
|
|
1316
|
+
exp.browser = {};
|
|
1317
|
+
if (entry.browser.import) exp.browser.import = _fileInfo(entry.browser.import);
|
|
1318
|
+
if (entry.browser.require) exp.browser.import = _fileInfo(entry.browser.require);
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
if (entry.import) exp.import = _fileInfo(entry.import);
|
|
1322
|
+
if (entry.require) exp.require = _fileInfo(entry.require);
|
|
1323
|
+
if (entry.types) exp.types = _fileInfo(entry.types);
|
|
1324
|
+
exp.default = _fileInfo(entry.default);
|
|
1325
|
+
return [chalk.green(path.join(pkg.name, exportPath)), exp];
|
|
1326
|
+
}));
|
|
1103
1327
|
logger.log(treeify.asTree(tree, true, true));
|
|
1104
1328
|
}
|
|
1105
1329
|
|
|
1106
1330
|
async function check(options) {
|
|
1107
|
-
const {
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1331
|
+
const {
|
|
1332
|
+
cwd,
|
|
1333
|
+
strict,
|
|
1334
|
+
tsconfig = "tsconfig.json"
|
|
1335
|
+
} = options;
|
|
1336
|
+
const pkg = await _loadPkgWithReporting({
|
|
1337
|
+
cwd
|
|
1338
|
+
});
|
|
1339
|
+
const config = await _loadConfig({
|
|
1340
|
+
cwd
|
|
1341
|
+
});
|
|
1342
|
+
const ctx = await _resolveBuildContext({
|
|
1343
|
+
config,
|
|
1344
|
+
cwd,
|
|
1345
|
+
pkg,
|
|
1346
|
+
tsconfig
|
|
1347
|
+
});
|
|
1348
|
+
|
|
1111
1349
|
_printPackageTree(ctx);
|
|
1350
|
+
|
|
1112
1351
|
if (strict) {
|
|
1113
1352
|
const missingFiles = [];
|
|
1353
|
+
|
|
1114
1354
|
for (const [, exp] of Object.entries(ctx.exports || {})) {
|
|
1115
1355
|
if (exp.source && !_fileExists(path.resolve(cwd, exp.source))) {
|
|
1116
1356
|
missingFiles.push(exp.source);
|
|
1117
1357
|
}
|
|
1358
|
+
|
|
1118
1359
|
if (exp.require && !_fileExists(path.resolve(cwd, exp.require))) {
|
|
1119
1360
|
missingFiles.push(exp.require);
|
|
1120
1361
|
}
|
|
1362
|
+
|
|
1121
1363
|
if (exp.import && !_fileExists(path.resolve(cwd, exp.import))) {
|
|
1122
1364
|
missingFiles.push(exp.import);
|
|
1123
1365
|
}
|
|
1366
|
+
|
|
1124
1367
|
if (exp.types && !_fileExists(path.resolve(cwd, exp.types))) {
|
|
1125
1368
|
missingFiles.push(exp.types);
|
|
1126
1369
|
}
|
|
1127
1370
|
}
|
|
1371
|
+
|
|
1128
1372
|
if (missingFiles.length) {
|
|
1129
1373
|
throw new Error("missing files");
|
|
1130
1374
|
}
|
|
1375
|
+
|
|
1131
1376
|
const _paths = {
|
|
1132
1377
|
require: [],
|
|
1133
1378
|
import: []
|
|
1134
1379
|
};
|
|
1380
|
+
|
|
1135
1381
|
for (const [exportPath, exp] of Object.entries(ctx.exports || {})) {
|
|
1136
|
-
if (!exp._exported)
|
|
1137
|
-
|
|
1138
|
-
if (exp.
|
|
1139
|
-
_paths.require.push(exportPath);
|
|
1140
|
-
if (exp.import)
|
|
1141
|
-
_paths.import.push(exportPath);
|
|
1382
|
+
if (!exp._exported) continue;
|
|
1383
|
+
if (exp.require) _paths.require.push(exportPath);
|
|
1384
|
+
if (exp.import) _paths.import.push(exportPath);
|
|
1142
1385
|
}
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1386
|
+
|
|
1387
|
+
const external = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.devDependencies || {}));
|
|
1388
|
+
|
|
1146
1389
|
if (_paths.import.length) {
|
|
1147
|
-
const code = _paths.import.map(
|
|
1390
|
+
const code = _paths.import.map(id => "import('".concat(id, "')")).join("\n");
|
|
1391
|
+
|
|
1148
1392
|
try {
|
|
1149
1393
|
const esbuildResult = await esbuild$1.build({
|
|
1150
1394
|
external,
|
|
@@ -1159,29 +1403,34 @@ async function check(options) {
|
|
|
1159
1403
|
outfile: "/dev/null",
|
|
1160
1404
|
platform: "node"
|
|
1161
1405
|
});
|
|
1406
|
+
|
|
1162
1407
|
if (esbuildResult.warnings.length > 0) {
|
|
1163
1408
|
console.warn(...esbuildResult.warnings);
|
|
1164
1409
|
}
|
|
1165
1410
|
} catch (err) {
|
|
1166
|
-
const {
|
|
1411
|
+
const {
|
|
1412
|
+
errors
|
|
1413
|
+
} = err;
|
|
1414
|
+
|
|
1167
1415
|
for (const _err of errors) {
|
|
1168
1416
|
if (_err.location) {
|
|
1169
1417
|
console.log(chalk.red("error"), _err.detail || _err.text);
|
|
1170
|
-
console.log(
|
|
1171
|
-
console.log(
|
|
1172
|
-
"in",
|
|
1173
|
-
`./${_err.location.file}:${_err.location.line}:${_err.location.column}`
|
|
1174
|
-
);
|
|
1418
|
+
console.log("".concat(_err.location.line, " | ").concat(_err.location.lineText));
|
|
1419
|
+
console.log("in", "./".concat(_err.location.file, ":").concat(_err.location.line, ":").concat(_err.location.column));
|
|
1175
1420
|
} else {
|
|
1176
1421
|
console.log(_err.detail || _err.text);
|
|
1177
1422
|
}
|
|
1423
|
+
|
|
1178
1424
|
console.log();
|
|
1179
1425
|
}
|
|
1426
|
+
|
|
1180
1427
|
process.exit(1);
|
|
1181
1428
|
}
|
|
1182
1429
|
}
|
|
1430
|
+
|
|
1183
1431
|
if (_paths.require.length) {
|
|
1184
|
-
const code = _paths.require.map(
|
|
1432
|
+
const code = _paths.require.map(id => "require('".concat(id, "')")).join("\n");
|
|
1433
|
+
|
|
1185
1434
|
const esbuildResult = await esbuild$1.build({
|
|
1186
1435
|
external,
|
|
1187
1436
|
stdin: {
|
|
@@ -1194,9 +1443,11 @@ async function check(options) {
|
|
|
1194
1443
|
outfile: "/dev/null",
|
|
1195
1444
|
platform: "node"
|
|
1196
1445
|
});
|
|
1446
|
+
|
|
1197
1447
|
if (esbuildResult.errors.length > 0) {
|
|
1198
1448
|
throw new Error(esbuildResult.errors.join(", "));
|
|
1199
1449
|
}
|
|
1450
|
+
|
|
1200
1451
|
if (esbuildResult.warnings.length > 0) {
|
|
1201
1452
|
console.warn(...esbuildResult.warnings);
|
|
1202
1453
|
}
|
|
@@ -1206,102 +1457,115 @@ async function check(options) {
|
|
|
1206
1457
|
|
|
1207
1458
|
function _resolveWatchTasks(ctx) {
|
|
1208
1459
|
var _a, _b, _c, _d, _e;
|
|
1209
|
-
|
|
1210
|
-
const
|
|
1460
|
+
|
|
1461
|
+
const {
|
|
1462
|
+
cwd,
|
|
1463
|
+
pkg,
|
|
1464
|
+
target
|
|
1465
|
+
} = ctx;
|
|
1211
1466
|
const tasks = [];
|
|
1212
|
-
const exports = Object.entries(ctx.exports || {}).map(
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1467
|
+
const exports = Object.entries(ctx.exports || {}).map(_ref12 => {
|
|
1468
|
+
let [_path, exp] = _ref12;
|
|
1469
|
+
return _objectSpread({
|
|
1470
|
+
_path
|
|
1471
|
+
}, exp);
|
|
1472
|
+
});
|
|
1473
|
+
const dtsTask = {
|
|
1474
|
+
type: "watch:dts",
|
|
1475
|
+
entries: []
|
|
1476
|
+
};
|
|
1216
1477
|
const rollupTasks = {};
|
|
1478
|
+
|
|
1217
1479
|
function _addRollupTaskEntry(format, runtime, entry) {
|
|
1218
|
-
const buildId =
|
|
1219
|
-
|
|
1480
|
+
const buildId = "".concat(format, ":").concat(runtime);
|
|
1481
|
+
|
|
1482
|
+
if (rollupTasks[buildId]) {
|
|
1483
|
+
rollupTasks[buildId].entries.push(entry);
|
|
1484
|
+
} else {
|
|
1220
1485
|
rollupTasks[buildId] = {
|
|
1221
1486
|
type: "watch:js",
|
|
1222
1487
|
buildId,
|
|
1223
1488
|
entries: [entry],
|
|
1224
1489
|
runtime,
|
|
1225
1490
|
format,
|
|
1226
|
-
target:
|
|
1491
|
+
target: target[runtime]
|
|
1227
1492
|
};
|
|
1228
|
-
} else {
|
|
1229
|
-
rollupTasks[buildId].entries.push(entry);
|
|
1230
1493
|
}
|
|
1231
1494
|
}
|
|
1495
|
+
|
|
1232
1496
|
for (const exp of exports) {
|
|
1233
1497
|
const importId = path.join(pkg.name, exp._path);
|
|
1498
|
+
|
|
1234
1499
|
if (exp.types) {
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
targetPath: exp.types
|
|
1242
|
-
};
|
|
1243
|
-
}
|
|
1500
|
+
dtsTask.entries.push({
|
|
1501
|
+
importId,
|
|
1502
|
+
exportPath: exp._path,
|
|
1503
|
+
sourcePath: exp.source,
|
|
1504
|
+
targetPath: exp.types
|
|
1505
|
+
});
|
|
1244
1506
|
}
|
|
1245
1507
|
}
|
|
1508
|
+
|
|
1246
1509
|
for (const exp of exports) {
|
|
1247
1510
|
const output = exp.require;
|
|
1248
|
-
if (!output)
|
|
1249
|
-
|
|
1511
|
+
if (!output) continue;
|
|
1512
|
+
|
|
1250
1513
|
_addRollupTaskEntry("commonjs", ctx.runtime, {
|
|
1251
1514
|
path: exp._path,
|
|
1252
1515
|
source: exp.source,
|
|
1253
1516
|
output
|
|
1254
1517
|
});
|
|
1255
1518
|
}
|
|
1519
|
+
|
|
1256
1520
|
for (const exp of exports) {
|
|
1257
1521
|
const output = (_a = exp.browser) == null ? void 0 : _a.require;
|
|
1258
|
-
if (!output)
|
|
1259
|
-
|
|
1522
|
+
if (!output) continue;
|
|
1523
|
+
|
|
1260
1524
|
_addRollupTaskEntry("commonjs", "browser", {
|
|
1261
1525
|
path: exp._path,
|
|
1262
1526
|
source: ((_b = exp.browser) == null ? void 0 : _b.source) || exp.source,
|
|
1263
1527
|
output
|
|
1264
1528
|
});
|
|
1265
1529
|
}
|
|
1530
|
+
|
|
1266
1531
|
for (const exp of exports) {
|
|
1267
1532
|
const output = exp.import;
|
|
1268
|
-
if (!output)
|
|
1269
|
-
|
|
1533
|
+
if (!output) continue;
|
|
1534
|
+
|
|
1270
1535
|
_addRollupTaskEntry("esm", ctx.runtime, {
|
|
1271
1536
|
path: exp._path,
|
|
1272
1537
|
source: exp.source,
|
|
1273
1538
|
output
|
|
1274
1539
|
});
|
|
1275
1540
|
}
|
|
1541
|
+
|
|
1276
1542
|
for (const exp of exports) {
|
|
1277
1543
|
const output = (_c = exp.browser) == null ? void 0 : _c.import;
|
|
1278
|
-
if (!output)
|
|
1279
|
-
|
|
1544
|
+
if (!output) continue;
|
|
1545
|
+
|
|
1280
1546
|
_addRollupTaskEntry("esm", "browser", {
|
|
1281
1547
|
path: exp._path,
|
|
1282
1548
|
source: ((_d = exp.browser) == null ? void 0 : _d.source) || exp.source,
|
|
1283
1549
|
output
|
|
1284
1550
|
});
|
|
1285
1551
|
}
|
|
1286
|
-
|
|
1552
|
+
|
|
1553
|
+
if (dtsTask.entries.length) {
|
|
1554
|
+
tasks.push(dtsTask);
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1287
1557
|
tasks.push(...Object.values(rollupTasks));
|
|
1558
|
+
|
|
1288
1559
|
for (const exp of exports) {
|
|
1289
1560
|
if (exp._exported && exp._path !== ".") {
|
|
1290
1561
|
const relativeTargetPath = (((_e = exp.browser) == null ? void 0 : _e.import) || exp.import || "").replace(/\.[^/.]+$/, "");
|
|
1562
|
+
|
|
1291
1563
|
if (relativeTargetPath) {
|
|
1292
|
-
fs$1.writeFileSync(
|
|
1293
|
-
path.resolve(cwd, `${exp._path}.js`),
|
|
1294
|
-
[
|
|
1295
|
-
`// AUTO-GENERATED \u2013 DO NOT EDIT`,
|
|
1296
|
-
``,
|
|
1297
|
-
`export {default} from '${relativeTargetPath}'`,
|
|
1298
|
-
`export * from '${relativeTargetPath}'`,
|
|
1299
|
-
``
|
|
1300
|
-
].join("\n")
|
|
1301
|
-
);
|
|
1564
|
+
fs$1.writeFileSync(path.resolve(cwd, "".concat(exp._path, ".js")), ["// AUTO-GENERATED \u2013 DO NOT EDIT", "", "export * from '".concat(relativeTargetPath, "'"), ""].join("\n"));
|
|
1302
1565
|
}
|
|
1303
1566
|
}
|
|
1304
1567
|
}
|
|
1568
|
+
|
|
1305
1569
|
return tasks;
|
|
1306
1570
|
}
|
|
1307
1571
|
|
|
@@ -1310,13 +1574,18 @@ function _globFiles(patterns) {
|
|
|
1310
1574
|
}
|
|
1311
1575
|
|
|
1312
1576
|
function _watchFiles(patterns) {
|
|
1313
|
-
return new Observable(
|
|
1577
|
+
return new Observable(observer => {
|
|
1314
1578
|
const watcher = chokidar.watch(patterns, {
|
|
1315
1579
|
ignoreInitial: true
|
|
1316
1580
|
});
|
|
1581
|
+
|
|
1317
1582
|
function _handleFileEvent(type, file) {
|
|
1318
|
-
observer.next({
|
|
1583
|
+
observer.next({
|
|
1584
|
+
type,
|
|
1585
|
+
file
|
|
1586
|
+
});
|
|
1319
1587
|
}
|
|
1588
|
+
|
|
1320
1589
|
watcher.on("all", _handleFileEvent);
|
|
1321
1590
|
return () => {
|
|
1322
1591
|
watcher.off("all", _handleFileEvent);
|
|
@@ -1326,69 +1595,76 @@ function _watchFiles(patterns) {
|
|
|
1326
1595
|
}
|
|
1327
1596
|
|
|
1328
1597
|
async function _watchConfigFiles(options) {
|
|
1329
|
-
const {
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
console.log(chalk.blue("info "), path.relative(cwd, fileEvent.file), "changed");
|
|
1355
|
-
console.log("");
|
|
1356
|
-
return files.slice(0);
|
|
1357
|
-
}
|
|
1358
|
-
return files;
|
|
1359
|
-
}, initialFiles),
|
|
1360
|
-
startWith(initialFiles),
|
|
1361
|
-
distinctUntilChanged()
|
|
1362
|
-
);
|
|
1598
|
+
const {
|
|
1599
|
+
cwd
|
|
1600
|
+
} = options;
|
|
1601
|
+
const initialFiles = await _globFiles([path.resolve(cwd, "package.json"), path.resolve(cwd, "package.config.cjs"), path.resolve(cwd, "package.config.js"), path.resolve(cwd, "package.config.ts")]);
|
|
1602
|
+
|
|
1603
|
+
const fileEvent$ = _watchFiles([path.resolve(cwd, "package.json"), path.resolve(cwd, "package.config.cjs"), path.resolve(cwd, "package.config.js"), path.resolve(cwd, "package.config.ts")]);
|
|
1604
|
+
|
|
1605
|
+
return fileEvent$.pipe(scan((files, fileEvent) => {
|
|
1606
|
+
if (fileEvent.type === "add") {
|
|
1607
|
+
return files.concat(fileEvent.file);
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
if (fileEvent.type === "unlink") {
|
|
1611
|
+
return files.filter(f => f !== fileEvent.file);
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
if (fileEvent.type === "change") {
|
|
1615
|
+
console.log("--------------------------------------------------------------------------------");
|
|
1616
|
+
console.log(chalk.blue("info "), path.relative(cwd, fileEvent.file), "changed");
|
|
1617
|
+
console.log("");
|
|
1618
|
+
return files.slice(0);
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
return files;
|
|
1622
|
+
}, initialFiles), startWith(initialFiles), distinctUntilChanged());
|
|
1363
1623
|
}
|
|
1364
1624
|
|
|
1365
1625
|
async function watch(options) {
|
|
1366
|
-
const {
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1626
|
+
const {
|
|
1627
|
+
cwd,
|
|
1628
|
+
tsconfig = "tsconfig.json"
|
|
1629
|
+
} = options;
|
|
1630
|
+
const configFiles$ = await _watchConfigFiles({
|
|
1631
|
+
cwd
|
|
1632
|
+
});
|
|
1633
|
+
const ctx$ = configFiles$.pipe(switchMap(async configFiles => {
|
|
1634
|
+
const _files = configFiles.map(f => path.relative(cwd, f));
|
|
1635
|
+
|
|
1636
|
+
const packageJsonPath = _files.find(f => f === "package.json");
|
|
1637
|
+
|
|
1638
|
+
if (!packageJsonPath) {
|
|
1639
|
+
throw new Error("missing package.json");
|
|
1640
|
+
}
|
|
1641
|
+
|
|
1642
|
+
const pkg = await _loadPkgWithReporting({
|
|
1643
|
+
cwd
|
|
1644
|
+
});
|
|
1645
|
+
const config = await _loadConfig({
|
|
1646
|
+
cwd
|
|
1647
|
+
});
|
|
1648
|
+
return _resolveBuildContext({
|
|
1649
|
+
config,
|
|
1650
|
+
cwd,
|
|
1651
|
+
pkg,
|
|
1652
|
+
tsconfig
|
|
1653
|
+
});
|
|
1654
|
+
}));
|
|
1655
|
+
ctx$.subscribe(async ctx => {
|
|
1381
1656
|
const watchTasks = _resolveWatchTasks(ctx);
|
|
1657
|
+
|
|
1382
1658
|
for (const task of watchTasks) {
|
|
1383
1659
|
const handler = _watchTaskHandlers[task.type];
|
|
1384
1660
|
const result$ = handler.exec(ctx, task);
|
|
1385
1661
|
result$.subscribe({
|
|
1386
|
-
error:
|
|
1662
|
+
error: err => {
|
|
1387
1663
|
ctx.logger.error(err);
|
|
1388
1664
|
ctx.logger.log();
|
|
1389
1665
|
process.exit(1);
|
|
1390
1666
|
},
|
|
1391
|
-
next:
|
|
1667
|
+
next: result => {
|
|
1392
1668
|
handler.complete(ctx, task, result);
|
|
1393
1669
|
},
|
|
1394
1670
|
complete: () => {
|