@sanity/pkg-utils 1.17.3 → 1.19.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/{build-6fac40bf.js → build-bcb33ba5.js} +19 -63
- package/dist/_chunks/build-bcb33ba5.js.map +1 -0
- package/dist/_chunks/{buildAction-ff3e6d24.js → buildAction-f240dab8.js} +8 -38
- package/dist/_chunks/buildAction-f240dab8.js.map +1 -0
- package/dist/_chunks/{check-87cbb6cc.js → check-1ea361f5.js} +26 -81
- package/dist/_chunks/check-1ea361f5.js.map +1 -0
- package/dist/_chunks/{checkAction-e7e455d4.js → checkAction-16be1201.js} +5 -22
- package/dist/_chunks/checkAction-16be1201.js.map +1 -0
- package/dist/_chunks/{_handleError-869dec25.js → handleError-65cf3242.js} +3 -8
- package/dist/_chunks/handleError-65cf3242.js.map +1 -0
- package/dist/_chunks/{index-fbba5480.js → index-79fdb33f.js} +105 -282
- package/dist/_chunks/index-79fdb33f.js.map +1 -0
- package/dist/_chunks/{_resolveBuildContext-7ca7e64e.js → resolveBuildContext-f2feec19.js} +63 -184
- package/dist/_chunks/resolveBuildContext-f2feec19.js.map +1 -0
- package/dist/_chunks/{watch-2ea1243e.js → watch-02c85f8a.js} +25 -80
- package/dist/_chunks/watch-02c85f8a.js.map +1 -0
- package/dist/_chunks/{watchAction-10e52cbc.js → watchAction-9cb9681b.js} +8 -41
- package/dist/_chunks/watchAction-9cb9681b.js.map +1 -0
- package/dist/cli.js +4 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +44 -46
- package/dist/index.esm.js +217 -560
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +24 -62
- package/dist/index.js.map +1 -1
- package/package.json +50 -1
- package/src/cli/buildAction.ts +2 -2
- package/src/cli/checkAction.ts +2 -2
- package/src/cli/{_handleError.ts → handleError.ts} +1 -1
- package/src/cli/watchAction.ts +2 -2
- package/src/node/build.ts +11 -11
- package/src/node/check.ts +11 -11
- package/src/node/{_core → core}/config/defineConfig.ts +0 -0
- package/src/node/{_core/config/_findConfigFile.ts → core/config/findConfigFile.ts} +3 -3
- package/src/node/core/config/index.ts +4 -0
- package/src/node/{_core/config/_loadConfig.ts → core/config/loadConfig.ts} +3 -3
- package/src/node/{_core/config/_resolveConfigProperty.ts → core/config/resolveConfigProperty.ts} +1 -1
- package/src/node/{_core → core}/config/types.ts +0 -0
- package/src/node/{_core/_constants.ts → core/constants.ts} +1 -1
- package/src/node/{_core → core}/contexts/buildContext.ts +5 -5
- package/src/node/{_core → core}/contexts/index.ts +0 -0
- package/src/node/core/defaults.ts +7 -0
- package/src/node/core/findCommonPath.test.ts +9 -0
- package/src/node/{_core/_findCommonPath.ts → core/findCommonPath.ts} +3 -3
- package/src/node/{_core → core}/index.ts +3 -3
- package/src/node/{_core/_isRecord.ts → core/isRecord.ts} +1 -1
- package/src/node/core/pkg/index.ts +4 -0
- package/src/node/{_core/pkg/_loadPkg.ts → core/pkg/loadPkg.ts} +4 -4
- package/src/node/{_core/pkg/_loadPkgWithReporting.ts → core/pkg/loadPkgWithReporting.ts} +6 -6
- package/src/node/{_core/pkg/_parseExports.ts → core/pkg/parseExports.ts} +7 -7
- package/src/node/{_core/pkg/_types.ts → core/pkg/types.ts} +1 -1
- package/src/node/{_core/pkg/_validateExports.ts → core/pkg/validateExports.ts} +5 -5
- package/src/node/{_core/pkg/_validatePkg.ts → core/pkg/validatePkg.ts} +2 -2
- package/src/node/core/ts/index.ts +1 -0
- package/src/node/{_core/ts/_loadTSConfig.ts → core/ts/loadTSConfig.ts} +1 -1
- package/src/node/{_getFilesize.ts → getFilesize.ts} +1 -1
- package/src/node/globFiles.ts +5 -0
- package/src/node/index.ts +3 -3
- package/src/node/{_printExtractMessages.ts → printExtractMessages.ts} +2 -2
- package/src/node/{_printPackageTree.ts → printPackageTree.ts} +17 -17
- package/src/node/{_resolveBrowserTarget.ts → resolveBrowserTarget.ts} +2 -2
- package/src/node/{_resolveBrowserslistVersions.ts → resolveBrowserslistVersions.ts} +11 -11
- package/src/node/{_resolveBuildContext.ts → resolveBuildContext.ts} +28 -28
- package/src/node/{_resolveBuildTasks.ts → resolveBuildTasks.ts} +13 -13
- package/src/node/{_resolveNodeTarget.ts → resolveNodeTarget.ts} +2 -2
- package/src/node/{_resolveWatchTasks.ts → resolveWatchTasks.ts} +11 -11
- package/src/node/{_spinner.ts → spinner.ts} +1 -1
- package/src/node/{_tasks/dts/_DtsError.ts → tasks/dts/DtsError.ts} +1 -1
- package/src/node/{_tasks/dts/_buildTypes.ts → tasks/dts/buildTypes.ts} +1 -1
- package/src/node/{_tasks/dts/_createApiExtractorConfig.ts → tasks/dts/createApiExtractorConfig.ts} +1 -1
- package/src/node/{_tasks/dts/_createTSDocConfig.ts → tasks/dts/createTSDocConfig.ts} +1 -1
- package/src/node/{_tasks/dts/_doExtract.ts → tasks/dts/doExtract.ts} +14 -20
- package/src/node/{_tasks/dts/_dtsTask.ts → tasks/dts/dtsTask.ts} +10 -10
- package/src/node/{_tasks/dts/_dtsWatchTask.ts → tasks/dts/dtsWatchTask.ts} +10 -10
- package/src/node/tasks/dts/extractModuleBlocks.ts +45 -0
- package/src/node/{_tasks/dts/_extractTypes.ts → tasks/dts/extractTypes.ts} +20 -10
- package/src/node/{_tasks/dts/_getExtractMessagesConfig.ts → tasks/dts/getExtractMessagesConfig.ts} +12 -12
- package/src/node/tasks/dts/index.ts +4 -0
- package/src/node/{_tasks/dts/_types.ts → tasks/dts/types.ts} +3 -3
- package/src/node/tasks/index.ts +19 -0
- package/src/node/tasks/rollup/index.ts +2 -0
- package/src/node/{_tasks/rollup/_resolveRollupConfig.ts → tasks/rollup/resolveRollupConfig.ts} +16 -11
- package/src/node/{_tasks/rollup/_rollupTask.ts → tasks/rollup/rollupTask.ts} +7 -7
- package/src/node/{_tasks/rollup/_rollupWatchTask.ts → tasks/rollup/rollupWatchTask.ts} +4 -4
- package/src/node/tasks/types.ts +57 -0
- package/src/node/watch.ts +13 -13
- package/src/node/{_watchConfigFiles.ts → watchConfigFiles.ts} +5 -5
- package/src/node/{_watchFiles.ts → watchFiles.ts} +5 -5
- package/dist/_chunks/_handleError-869dec25.js.map +0 -1
- package/dist/_chunks/_resolveBuildContext-7ca7e64e.js.map +0 -1
- package/dist/_chunks/build-6fac40bf.js.map +0 -1
- package/dist/_chunks/buildAction-ff3e6d24.js.map +0 -1
- package/dist/_chunks/check-87cbb6cc.js.map +0 -1
- package/dist/_chunks/checkAction-e7e455d4.js.map +0 -1
- package/dist/_chunks/index-fbba5480.js.map +0 -1
- package/dist/_chunks/watch-2ea1243e.js.map +0 -1
- package/dist/_chunks/watchAction-10e52cbc.js.map +0 -1
- package/src/node/_core/_defaults.ts +0 -9
- package/src/node/_core/_findCommonPath.test.ts +0 -9
- package/src/node/_core/config/index.ts +0 -4
- package/src/node/_core/pkg/index.ts +0 -4
- package/src/node/_core/ts/index.ts +0 -1
- package/src/node/_globFiles.ts +0 -5
- package/src/node/_tasks/_types.ts +0 -57
- package/src/node/_tasks/dts/_declareModuleFix.ts +0 -99
- package/src/node/_tasks/dts/index.ts +0 -4
- package/src/node/_tasks/index.ts +0 -19
- package/src/node/_tasks/rollup/index.ts +0 -2
package/dist/index.js
CHANGED
|
@@ -3,105 +3,67 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
var index = require('./_chunks/index-fbba5480.js');
|
|
12
|
-
|
|
13
|
-
var check = require('./_chunks/check-87cbb6cc.js');
|
|
14
|
-
|
|
15
|
-
var watch = require('./_chunks/watch-2ea1243e.js');
|
|
16
|
-
|
|
6
|
+
var resolveBuildContext = require('./_chunks/resolveBuildContext-f2feec19.js');
|
|
7
|
+
var build = require('./_chunks/build-bcb33ba5.js');
|
|
8
|
+
var index = require('./_chunks/index-79fdb33f.js');
|
|
9
|
+
var check = require('./_chunks/check-1ea361f5.js');
|
|
10
|
+
var watch = require('./_chunks/watch-02c85f8a.js');
|
|
17
11
|
require('path');
|
|
18
|
-
|
|
19
12
|
require('esbuild-register/dist/node');
|
|
20
|
-
|
|
21
13
|
require('pkg-up');
|
|
22
|
-
|
|
23
14
|
require('fs/promises');
|
|
24
|
-
|
|
25
15
|
require('find-config');
|
|
26
|
-
|
|
27
16
|
require('chalk');
|
|
28
|
-
|
|
29
17
|
require('zod');
|
|
30
|
-
|
|
31
18
|
require('typescript');
|
|
32
|
-
|
|
33
19
|
require('browserslist');
|
|
34
|
-
|
|
35
20
|
require('fs');
|
|
36
|
-
|
|
37
21
|
require('rxjs');
|
|
38
|
-
|
|
39
22
|
require('util');
|
|
40
|
-
|
|
41
23
|
require('rimraf');
|
|
42
|
-
|
|
43
24
|
require('@microsoft/api-extractor');
|
|
44
|
-
|
|
45
25
|
require('mkdirp');
|
|
46
|
-
|
|
47
26
|
require('prettier');
|
|
48
|
-
|
|
49
27
|
require('@microsoft/tsdoc-config');
|
|
50
|
-
|
|
51
28
|
require('jsonc-parser');
|
|
52
|
-
|
|
29
|
+
require('recast');
|
|
30
|
+
require('recast/parsers/typescript');
|
|
53
31
|
require('rollup');
|
|
54
|
-
|
|
55
32
|
require('@rollup/plugin-alias');
|
|
56
|
-
|
|
57
33
|
require('@rollup/plugin-babel');
|
|
58
|
-
|
|
59
34
|
require('@rollup/plugin-commonjs');
|
|
60
|
-
|
|
61
35
|
require('@rollup/plugin-json');
|
|
62
|
-
|
|
63
36
|
require('@rollup/plugin-node-resolve');
|
|
64
|
-
|
|
65
37
|
require('@rollup/plugin-replace');
|
|
66
|
-
|
|
67
38
|
require('rollup-plugin-esbuild');
|
|
68
|
-
|
|
69
39
|
require('rollup-plugin-terser');
|
|
70
|
-
|
|
71
40
|
require('esbuild');
|
|
72
|
-
|
|
73
41
|
require('treeify');
|
|
74
|
-
|
|
75
42
|
require('pretty-bytes');
|
|
76
|
-
|
|
77
43
|
require('rxjs/operators');
|
|
78
|
-
|
|
79
44
|
require('globby');
|
|
80
|
-
|
|
81
45
|
require('chokidar');
|
|
82
|
-
|
|
83
46
|
function defineConfig(configOptions) {
|
|
84
47
|
return configOptions;
|
|
85
48
|
}
|
|
86
|
-
|
|
87
|
-
exports.
|
|
88
|
-
exports.
|
|
89
|
-
exports.
|
|
90
|
-
exports.
|
|
91
|
-
exports.
|
|
92
|
-
exports.
|
|
93
|
-
exports.
|
|
94
|
-
exports.
|
|
95
|
-
exports._resolveConfigProperty = _resolveBuildContext._resolveConfigProperty;
|
|
96
|
-
exports._resolveBuildTasks = build._resolveBuildTasks;
|
|
49
|
+
exports.DEFAULT_BROWSERSLIST_QUERY = resolveBuildContext.DEFAULT_BROWSERSLIST_QUERY;
|
|
50
|
+
exports.MODULE_EXT = resolveBuildContext.MODULE_EXT;
|
|
51
|
+
exports.isRecord = resolveBuildContext.isRecord;
|
|
52
|
+
exports.loadConfig = resolveBuildContext.loadConfig;
|
|
53
|
+
exports.loadPkg = resolveBuildContext.loadPkg;
|
|
54
|
+
exports.loadPkgWithReporting = resolveBuildContext.loadPkgWithReporting;
|
|
55
|
+
exports.loadTSConfig = resolveBuildContext.loadTSConfig;
|
|
56
|
+
exports.parseExports = resolveBuildContext.parseExports;
|
|
57
|
+
exports.resolveConfigProperty = resolveBuildContext.resolveConfigProperty;
|
|
97
58
|
exports.build = build.build;
|
|
98
|
-
exports.
|
|
99
|
-
exports.
|
|
100
|
-
exports.
|
|
101
|
-
exports.
|
|
102
|
-
exports.
|
|
103
|
-
exports.
|
|
104
|
-
exports.
|
|
59
|
+
exports.resolveBuildTasks = build.resolveBuildTasks;
|
|
60
|
+
exports.buildTaskHandlers = index.buildTaskHandlers;
|
|
61
|
+
exports.dtsTask = index.dtsTask;
|
|
62
|
+
exports.dtsWatchTask = index.dtsWatchTask;
|
|
63
|
+
exports.getExtractMessagesConfig = index.getExtractMessagesConfig;
|
|
64
|
+
exports.rollupTask = index.rollupTask;
|
|
65
|
+
exports.rollupWatchTask = index.rollupWatchTask;
|
|
66
|
+
exports.watchTaskHandlers = index.watchTaskHandlers;
|
|
105
67
|
exports.check = check.check;
|
|
106
68
|
exports.watch = watch.watch;
|
|
107
69
|
exports.defineConfig = defineConfig;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/node/
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/node/core/config/defineConfig.ts"],"sourcesContent":["import {PkgConfigOptions} from './types'\n\n/** @public */\nexport function defineConfig(configOptions: PkgConfigOptions): PkgConfigOptions {\n return configOptions\n}\n"],"names":["defineConfig","configOptions"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,SAASA,YAAY,CAACC,aAAa,EAAE;EAC1C,OAAOA,aAAa;AACtB;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/pkg-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"author": "Sanity.io <hello@sanity.io>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Simple utilities for modern npm packages.",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@babel/core": "^7.19.0",
|
|
57
|
+
"@babel/types": "^7.19.0",
|
|
57
58
|
"@babel/plugin-proposal-object-rest-spread": "^7.18.9",
|
|
58
59
|
"@babel/preset-env": "^7.19.0",
|
|
59
60
|
"@microsoft/api-extractor": "^7.29.5",
|
|
@@ -77,6 +78,7 @@
|
|
|
77
78
|
"pkg-up": "^3.1.0",
|
|
78
79
|
"prettier": "^2.7.1",
|
|
79
80
|
"pretty-bytes": "^5.6.0",
|
|
81
|
+
"recast": "^0.21.5",
|
|
80
82
|
"rimraf": "^3.0.2",
|
|
81
83
|
"rollup": "^2.78.1",
|
|
82
84
|
"rollup-plugin-esbuild": "^4.9.3",
|
|
@@ -138,6 +140,11 @@
|
|
|
138
140
|
"url": "https://github.com/sanity-io/pkg-utils/issues"
|
|
139
141
|
},
|
|
140
142
|
"homepage": "https://github.com/sanity-io/pkg-utils#readme",
|
|
143
|
+
"commitlint": {
|
|
144
|
+
"extends": [
|
|
145
|
+
"@commitlint/config-conventional"
|
|
146
|
+
]
|
|
147
|
+
},
|
|
141
148
|
"publishConfig": {
|
|
142
149
|
"access": "public"
|
|
143
150
|
},
|
|
@@ -146,5 +153,47 @@
|
|
|
146
153
|
"overrides": {
|
|
147
154
|
"@sanity/pkg-utils": "workspace:*"
|
|
148
155
|
}
|
|
156
|
+
},
|
|
157
|
+
"prettier": {
|
|
158
|
+
"bracketSpacing": false,
|
|
159
|
+
"printWidth": 100,
|
|
160
|
+
"semi": false,
|
|
161
|
+
"singleQuote": true,
|
|
162
|
+
"tabWidth": 2,
|
|
163
|
+
"overrides": [
|
|
164
|
+
{
|
|
165
|
+
"files": [
|
|
166
|
+
"*.json5"
|
|
167
|
+
],
|
|
168
|
+
"options": {
|
|
169
|
+
"singleQuote": false,
|
|
170
|
+
"quoteProps": "preserve"
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"files": [
|
|
175
|
+
"*.yml"
|
|
176
|
+
],
|
|
177
|
+
"options": {
|
|
178
|
+
"singleQuote": false
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
]
|
|
182
|
+
},
|
|
183
|
+
"release": {
|
|
184
|
+
"extends": "@sanity/semantic-release-preset",
|
|
185
|
+
"branches": [
|
|
186
|
+
"+([0-9])?(.{+([0-9]),x}).x",
|
|
187
|
+
"main",
|
|
188
|
+
"next",
|
|
189
|
+
{
|
|
190
|
+
"name": "beta",
|
|
191
|
+
"prerelease": true
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
"name": "alpha",
|
|
195
|
+
"prerelease": true
|
|
196
|
+
}
|
|
197
|
+
]
|
|
149
198
|
}
|
|
150
199
|
}
|
package/src/cli/buildAction.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {build} from '../node/build'
|
|
2
|
-
import {
|
|
2
|
+
import {handleError} from './handleError'
|
|
3
3
|
|
|
4
4
|
export async function buildAction(options: {
|
|
5
5
|
emitDeclarationOnly?: boolean
|
|
@@ -14,6 +14,6 @@ export async function buildAction(options: {
|
|
|
14
14
|
tsconfig: options.tsconfig,
|
|
15
15
|
})
|
|
16
16
|
} catch (err) {
|
|
17
|
-
|
|
17
|
+
handleError(err)
|
|
18
18
|
}
|
|
19
19
|
}
|
package/src/cli/checkAction.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {check} from '../node/check'
|
|
2
|
-
import {
|
|
2
|
+
import {handleError} from './handleError'
|
|
3
3
|
|
|
4
4
|
export async function checkAction(options: {strict?: boolean; tsconfig?: string}): Promise<void> {
|
|
5
5
|
try {
|
|
@@ -9,6 +9,6 @@ export async function checkAction(options: {strict?: boolean; tsconfig?: string}
|
|
|
9
9
|
tsconfig: options.tsconfig,
|
|
10
10
|
})
|
|
11
11
|
} catch (err) {
|
|
12
|
-
|
|
12
|
+
handleError(err)
|
|
13
13
|
}
|
|
14
14
|
}
|
package/src/cli/watchAction.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {watch} from '../node/watch'
|
|
2
|
-
import {
|
|
2
|
+
import {handleError} from './handleError'
|
|
3
3
|
|
|
4
4
|
export async function watchAction(options: {strict?: boolean; tsconfig?: string}): Promise<void> {
|
|
5
5
|
try {
|
|
@@ -9,6 +9,6 @@ export async function watchAction(options: {strict?: boolean; tsconfig?: string}
|
|
|
9
9
|
tsconfig: options.tsconfig,
|
|
10
10
|
})
|
|
11
11
|
} catch (err) {
|
|
12
|
-
|
|
12
|
+
handleError(err)
|
|
13
13
|
}
|
|
14
14
|
}
|
package/src/node/build.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import {loadConfig, loadPkgWithReporting} from './core'
|
|
2
|
+
import {resolveBuildContext} from './resolveBuildContext'
|
|
3
|
+
import {resolveBuildTasks} from './resolveBuildTasks'
|
|
4
|
+
import {createSpinner} from './spinner'
|
|
5
|
+
import {BuildTask, TaskHandler, buildTaskHandlers} from './tasks'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Build the distribution files of a npm package.
|
|
@@ -31,18 +31,18 @@ export async function build(options: {
|
|
|
31
31
|
}): Promise<void> {
|
|
32
32
|
const {cwd, emitDeclarationOnly, strict = false, tsconfig: tsconfigOption} = options
|
|
33
33
|
|
|
34
|
-
const pkg = await
|
|
35
|
-
const config = await
|
|
34
|
+
const pkg = await loadPkgWithReporting({cwd})
|
|
35
|
+
const config = await loadConfig({cwd})
|
|
36
36
|
const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
|
|
37
|
-
const ctx = await
|
|
37
|
+
const ctx = await resolveBuildContext({config, cwd, emitDeclarationOnly, pkg, strict, tsconfig})
|
|
38
38
|
|
|
39
|
-
const buildTasks =
|
|
39
|
+
const buildTasks = resolveBuildTasks(ctx)
|
|
40
40
|
|
|
41
41
|
for (const task of buildTasks) {
|
|
42
|
-
const handler =
|
|
42
|
+
const handler = buildTaskHandlers[task.type] as TaskHandler<BuildTask>
|
|
43
43
|
const taskName = handler.name(ctx, task)
|
|
44
44
|
|
|
45
|
-
const spinner =
|
|
45
|
+
const spinner = createSpinner(taskName)
|
|
46
46
|
|
|
47
47
|
try {
|
|
48
48
|
const result = await handler.exec(ctx, task).toPromise()
|
package/src/node/check.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
import esbuild, {BuildFailure} from 'esbuild'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import {loadConfig, loadPkgWithReporting} from './core'
|
|
4
|
+
import {fileExists, printPackageTree} from './printPackageTree'
|
|
5
|
+
import {resolveBuildContext} from './resolveBuildContext'
|
|
6
6
|
|
|
7
7
|
/** @public */
|
|
8
8
|
export async function check(options: {
|
|
@@ -12,32 +12,32 @@ export async function check(options: {
|
|
|
12
12
|
}): Promise<void> {
|
|
13
13
|
const {cwd, strict = false, tsconfig: tsconfigOption} = options
|
|
14
14
|
|
|
15
|
-
const pkg = await
|
|
16
|
-
const config = await
|
|
15
|
+
const pkg = await loadPkgWithReporting({cwd})
|
|
16
|
+
const config = await loadConfig({cwd})
|
|
17
17
|
const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
|
|
18
|
-
const ctx = await
|
|
18
|
+
const ctx = await resolveBuildContext({config, cwd, pkg, strict, tsconfig})
|
|
19
19
|
const {logger} = ctx
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
printPackageTree(ctx)
|
|
22
22
|
|
|
23
23
|
if (strict) {
|
|
24
24
|
const missingFiles: string[] = []
|
|
25
25
|
|
|
26
26
|
// Check if there are missing files
|
|
27
27
|
for (const [, exp] of Object.entries(ctx.exports || {})) {
|
|
28
|
-
if (exp.source && !
|
|
28
|
+
if (exp.source && !fileExists(path.resolve(cwd, exp.source))) {
|
|
29
29
|
missingFiles.push(exp.source)
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
if (exp.require && !
|
|
32
|
+
if (exp.require && !fileExists(path.resolve(cwd, exp.require))) {
|
|
33
33
|
missingFiles.push(exp.require)
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
if (exp.import && !
|
|
36
|
+
if (exp.import && !fileExists(path.resolve(cwd, exp.import))) {
|
|
37
37
|
missingFiles.push(exp.import)
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
if (exp.types && !
|
|
40
|
+
if (exp.types && !fileExists(path.resolve(cwd, exp.types))) {
|
|
41
41
|
missingFiles.push(exp.types)
|
|
42
42
|
}
|
|
43
43
|
}
|
|
File without changes
|
|
@@ -9,7 +9,7 @@ const CONFIG_FILE_NAMES = [
|
|
|
9
9
|
'package.config.mjs',
|
|
10
10
|
]
|
|
11
11
|
|
|
12
|
-
export async function
|
|
12
|
+
export async function findConfigFile(cwd: string): Promise<string | undefined> {
|
|
13
13
|
const pkgJsonPath = findConfig('package.json', {cwd})
|
|
14
14
|
|
|
15
15
|
if (!pkgJsonPath) return undefined
|
|
@@ -19,7 +19,7 @@ export async function _findConfigFile(cwd: string): Promise<string | undefined>
|
|
|
19
19
|
for (const fileName of CONFIG_FILE_NAMES) {
|
|
20
20
|
const configPath = path.resolve(pkgPath, fileName)
|
|
21
21
|
|
|
22
|
-
const exists = await
|
|
22
|
+
const exists = await fileExists(configPath)
|
|
23
23
|
|
|
24
24
|
if (exists) {
|
|
25
25
|
return configPath
|
|
@@ -29,7 +29,7 @@ export async function _findConfigFile(cwd: string): Promise<string | undefined>
|
|
|
29
29
|
return undefined
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
async function
|
|
32
|
+
async function fileExists(filePath: string) {
|
|
33
33
|
try {
|
|
34
34
|
await stat(filePath)
|
|
35
35
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
import {register} from 'esbuild-register/dist/node'
|
|
3
3
|
import pkgUp from 'pkg-up'
|
|
4
|
-
import {
|
|
4
|
+
import {findConfigFile} from './findConfigFile'
|
|
5
5
|
import {PkgConfigOptions} from './types'
|
|
6
6
|
|
|
7
7
|
/** @internal */
|
|
8
|
-
export async function
|
|
8
|
+
export async function loadConfig(options: {cwd: string}): Promise<PkgConfigOptions | undefined> {
|
|
9
9
|
const {cwd} = options
|
|
10
10
|
|
|
11
11
|
const pkgPath = await pkgUp({cwd})
|
|
@@ -14,7 +14,7 @@ export async function _loadConfig(options: {cwd: string}): Promise<PkgConfigOpti
|
|
|
14
14
|
|
|
15
15
|
const root = path.dirname(pkgPath)
|
|
16
16
|
|
|
17
|
-
const configFile = await
|
|
17
|
+
const configFile = await findConfigFile(root)
|
|
18
18
|
|
|
19
19
|
if (!configFile) {
|
|
20
20
|
return undefined
|
|
File without changes
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import ts from 'typescript'
|
|
2
2
|
import {PkgExports, PkgRuntime, PkgConfigOptions} from '../config'
|
|
3
|
-
import {
|
|
3
|
+
import {PackageJSON} from '../pkg'
|
|
4
4
|
|
|
5
5
|
/** @internal */
|
|
6
|
-
export interface
|
|
6
|
+
export interface BuildFile {
|
|
7
7
|
type: 'asset' | 'chunk' | 'types'
|
|
8
8
|
path: string
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
/** @internal */
|
|
12
|
-
export interface
|
|
12
|
+
export interface BuildContext {
|
|
13
13
|
config?: PkgConfigOptions
|
|
14
14
|
cwd: string
|
|
15
15
|
distPath: string
|
|
16
16
|
emitDeclarationOnly: boolean
|
|
17
17
|
exports: PkgExports | undefined
|
|
18
18
|
external: string[]
|
|
19
|
-
files:
|
|
19
|
+
files: BuildFile[]
|
|
20
20
|
logger: {
|
|
21
21
|
log: (...args: unknown[]) => void
|
|
22
22
|
info: (...args: unknown[]) => void
|
|
@@ -24,7 +24,7 @@ export interface _BuildContext {
|
|
|
24
24
|
error: (...args: unknown[]) => void
|
|
25
25
|
success: (...args: unknown[]) => void
|
|
26
26
|
}
|
|
27
|
-
pkg:
|
|
27
|
+
pkg: PackageJSON
|
|
28
28
|
runtime: PkgRuntime
|
|
29
29
|
strict: boolean
|
|
30
30
|
target: Record<PkgRuntime, string[]>
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import {expect, test} from 'vitest'
|
|
2
|
+
import {findCommonDirPath} from './findCommonPath'
|
|
3
|
+
|
|
4
|
+
test('should find common parent directory of paths', () => {
|
|
5
|
+
expect(findCommonDirPath(['test/a', 'test/b/a'])).toBe('test')
|
|
6
|
+
expect(findCommonDirPath(['/test/a', '/test/b/a'])).toBe('/test')
|
|
7
|
+
expect(findCommonDirPath(['/test/a/b', '/test/a/b/c'])).toBe('/test/a')
|
|
8
|
+
expect(findCommonDirPath(['test/a/b', 'test/a/b', 'test/b/c', 'test/b/a'])).toBe('test')
|
|
9
|
+
})
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
|
|
3
|
-
export function
|
|
3
|
+
export function pathContains(containerPath: string, itemPath: string): boolean {
|
|
4
4
|
return !path.relative(containerPath, itemPath).startsWith('..')
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export function
|
|
7
|
+
export function findCommonDirPath(filePaths: string[]): string | undefined {
|
|
8
8
|
let ret: string | undefined = undefined
|
|
9
9
|
|
|
10
10
|
for (const filePath of filePaths) {
|
|
@@ -22,7 +22,7 @@ export function _findCommonDirPath(filePaths: string[]): string | undefined {
|
|
|
22
22
|
break
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
if (
|
|
25
|
+
if (pathContains(dirPath, ret)) {
|
|
26
26
|
ret = dirPath
|
|
27
27
|
break
|
|
28
28
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import fs from 'fs/promises'
|
|
2
2
|
import pkgUp from 'pkg-up'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import {PackageJSON} from './types'
|
|
4
|
+
import {validatePkg} from './validatePkg'
|
|
5
5
|
|
|
6
6
|
/** @internal */
|
|
7
|
-
export async function
|
|
7
|
+
export async function loadPkg(options: {cwd: string}): Promise<PackageJSON> {
|
|
8
8
|
const {cwd} = options
|
|
9
9
|
|
|
10
10
|
const pkgPath = await pkgUp({cwd})
|
|
@@ -13,5 +13,5 @@ export async function _loadPkg(options: {cwd: string}): Promise<_PackageJSON> {
|
|
|
13
13
|
|
|
14
14
|
const buf = await fs.readFile(pkgPath)
|
|
15
15
|
|
|
16
|
-
return
|
|
16
|
+
return validatePkg(JSON.parse(buf.toString()))
|
|
17
17
|
}
|
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
import chalk from 'chalk'
|
|
4
4
|
import {ZodError} from 'zod'
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import {loadPkg} from './loadPkg'
|
|
6
|
+
import {PackageJSON} from './types'
|
|
7
7
|
|
|
8
8
|
/** @internal */
|
|
9
|
-
export async function
|
|
9
|
+
export async function loadPkgWithReporting(options: {cwd: string}): Promise<PackageJSON> {
|
|
10
10
|
try {
|
|
11
|
-
return await
|
|
11
|
+
return await loadPkg(options)
|
|
12
12
|
} catch (err) {
|
|
13
13
|
if (err instanceof ZodError) {
|
|
14
14
|
for (const issue of err.issues) {
|
|
15
15
|
if (issue.code === 'invalid_type') {
|
|
16
16
|
console.log(
|
|
17
17
|
[
|
|
18
|
-
`${chalk.red('fail')} \`${
|
|
18
|
+
`${chalk.red('fail')} \`${formatPath(issue.path)}\` `,
|
|
19
19
|
`in ./package.json must be of type ${chalk.magenta(issue.expected)} `,
|
|
20
20
|
`(received ${chalk.magenta(issue.received)})`,
|
|
21
21
|
].join('')
|
|
@@ -30,7 +30,7 @@ export async function _loadPkgWithReporting(options: {cwd: string}): Promise<_Pa
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
function
|
|
33
|
+
function formatPath(segments: Array<string | number>) {
|
|
34
34
|
return segments
|
|
35
35
|
.map((s, idx) => {
|
|
36
36
|
if (idx === 0) return s
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {_isRecord} from '../_isRecord'
|
|
2
1
|
import {PkgExport} from '../config'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import {isRecord} from '../isRecord'
|
|
3
|
+
import {PackageJSON} from './types'
|
|
4
|
+
import {validateExports} from './validateExports'
|
|
5
5
|
|
|
6
6
|
/** @internal */
|
|
7
|
-
export function
|
|
8
|
-
pkg:
|
|
7
|
+
export function parseExports(options: {
|
|
8
|
+
pkg: PackageJSON
|
|
9
9
|
strict: boolean
|
|
10
10
|
}): (PkgExport & {_path: string})[] {
|
|
11
11
|
const {pkg, strict} = options
|
|
@@ -41,7 +41,7 @@ export function _parseExports(options: {
|
|
|
41
41
|
errors.push('package.json: `exports["./package.json"] must be "./package.json".')
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
} else if (
|
|
44
|
+
} else if (isRecord(exportEntry)) {
|
|
45
45
|
if (exportPath === '.') {
|
|
46
46
|
if (
|
|
47
47
|
exportEntry.require &&
|
|
@@ -89,7 +89,7 @@ export function _parseExports(options: {
|
|
|
89
89
|
|
|
90
90
|
const _exports = [rootExport, ...extraExports]
|
|
91
91
|
|
|
92
|
-
errors.push(...
|
|
92
|
+
errors.push(...validateExports(_exports, {pkg}))
|
|
93
93
|
|
|
94
94
|
if (errors.length) {
|
|
95
95
|
throw new Error('\n- ' + errors.join('\n- '))
|