@sanity/pkg-utils 1.8.1 → 1.8.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/{_build-0377061e.cjs → _build-3d61d85e.cjs} +10 -3
- package/dist/_build-3d61d85e.cjs.map +1 -0
- package/dist/{_buildAction-68633427.cjs → _buildAction-ba8138ff.cjs} +3 -5
- package/dist/{_buildAction-68633427.cjs.map → _buildAction-ba8138ff.cjs.map} +1 -1
- package/dist/{_check-11811a4d.cjs → _check-5f3f5a84.cjs} +30 -6
- package/dist/_check-5f3f5a84.cjs.map +1 -0
- package/dist/{_checkAction-386fe8d4.cjs → _checkAction-6ae8d321.cjs} +2 -2
- package/dist/{_checkAction-386fe8d4.cjs.map → _checkAction-6ae8d321.cjs.map} +1 -1
- package/dist/{_index-8cd98d8d.cjs → _index-bc62cfaa.cjs} +44 -39
- package/dist/_index-bc62cfaa.cjs.map +1 -0
- package/dist/{_watch-259b1e4f.cjs → _watch-925404b5.cjs} +10 -3
- package/dist/_watch-925404b5.cjs.map +1 -0
- package/dist/{_watchAction-a48d3934.cjs → _watchAction-e8317c50.cjs} +3 -5
- package/dist/{_watchAction-a48d3934.cjs.map → _watchAction-e8317c50.cjs.map} +1 -1
- package/dist/cli.cjs +4 -4
- package/dist/index.cjs +29 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +72 -40
- package/dist/index.js.map +1 -1
- package/dist/types/src/node/index.d.ts +9 -0
- package/package.json +15 -13
- package/src/node/_core/_constants.ts +13 -0
- package/src/node/_core/index.ts +1 -0
- package/src/node/_printPackageTree.ts +31 -6
- package/src/node/_resolveBuildTasks.ts +3 -2
- package/src/node/_resolveWatchTasks.ts +3 -2
- package/src/node/_tasks/dts/_buildTypes.ts +1 -0
- package/src/node/_tasks/dts/_createApiExtractorConfig.ts +13 -5
- package/src/node/_tasks/dts/_doExtract.ts +24 -35
- package/src/node/_tasks/dts/_extractTypes.ts +4 -4
- package/src/node/_tasks/rollup/_resolveRollupConfig.ts +3 -2
- package/src/node/watch.ts +1 -1
- package/dist/_build-0377061e.cjs.map +0 -1
- package/dist/_check-11811a4d.cjs.map +0 -1
- package/dist/_index-8cd98d8d.cjs.map +0 -1
- package/dist/_watch-259b1e4f.cjs.map +0 -1
|
@@ -120,6 +120,15 @@ export declare function _loadTSConfig(options: {
|
|
|
120
120
|
tsconfigPath: string
|
|
121
121
|
}): Promise<ts.ParsedCommandLine>
|
|
122
122
|
|
|
123
|
+
/** @internal */
|
|
124
|
+
export declare const _MODULE_EXT: Record<
|
|
125
|
+
'commonjs' | 'module',
|
|
126
|
+
{
|
|
127
|
+
commonjs: string
|
|
128
|
+
esm: string
|
|
129
|
+
}
|
|
130
|
+
>
|
|
131
|
+
|
|
123
132
|
/** @internal */
|
|
124
133
|
export declare interface _PackageJSON {
|
|
125
134
|
type: 'commonjs' | 'module'
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@sanity/pkg-utils",
|
|
4
|
-
"version": "1.8.
|
|
4
|
+
"version": "1.8.3",
|
|
5
5
|
"author": "Sanity.io <hello@sanity.io>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "Simple utilities for modern npm packages.",
|
|
@@ -37,19 +37,18 @@
|
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"scripts": {
|
|
40
|
-
"build": "
|
|
41
|
-
"
|
|
40
|
+
"build": "run-s clean build:pkg check:pkg",
|
|
41
|
+
"build:pkg": "node --experimental-loader ./scripts/_experimental-loader.js --no-warnings -r esbuild-register scripts/build",
|
|
42
|
+
"check:pkg": "node --experimental-loader ./scripts/_experimental-loader.js --no-warnings -r esbuild-register scripts/check",
|
|
43
|
+
"check:types": "tsc --build",
|
|
42
44
|
"clean": "rimraf dist test/env/__tmp__",
|
|
43
45
|
"commit": "cz",
|
|
44
46
|
"extract": "sanity-tsdoc etl --outDir etc/api/@sanity/pkg-utils --tsconfig tsconfig.dist.json",
|
|
45
47
|
"format": "prettier --write --cache --ignore-unknown .",
|
|
46
|
-
"lint": "eslint . --ext .cjs,.js,.ts",
|
|
47
|
-
"postbuild": "pnpm run check:package",
|
|
48
|
-
"prebuild": "pnpm run clean",
|
|
48
|
+
"lint": "eslint . --ext .cjs,.js,.ts,.tsx",
|
|
49
49
|
"prepublishOnly": "pnpm run build",
|
|
50
50
|
"release": "semantic-release",
|
|
51
51
|
"test": "vitest run",
|
|
52
|
-
"type-check": "tsc --build",
|
|
53
52
|
"watch": "node --experimental-loader ./scripts/_experimental-loader.js --no-warnings -r esbuild-register scripts/watch"
|
|
54
53
|
},
|
|
55
54
|
"dependencies": {
|
|
@@ -68,7 +67,6 @@
|
|
|
68
67
|
"cac": "^6.7.12",
|
|
69
68
|
"chalk": "^4.1.2",
|
|
70
69
|
"chokidar": "^3.5.3",
|
|
71
|
-
"cpx": "^1.5.0",
|
|
72
70
|
"esbuild": "^0.15.5",
|
|
73
71
|
"esbuild-register": "^3.3.3",
|
|
74
72
|
"find-config": "^1.0.0",
|
|
@@ -89,6 +87,7 @@
|
|
|
89
87
|
"devDependencies": {
|
|
90
88
|
"@commitlint/cli": "^17.0.3",
|
|
91
89
|
"@commitlint/config-conventional": "^17.0.3",
|
|
90
|
+
"@sanity/pkg-utils": "workspace:*",
|
|
92
91
|
"@sanity/semantic-release-preset": "^2.0.0",
|
|
93
92
|
"@types/babel__core": "^7.1.19",
|
|
94
93
|
"@types/cpx": "^1.5.2",
|
|
@@ -102,6 +101,7 @@
|
|
|
102
101
|
"@typescript-eslint/eslint-plugin": "^5.35.1",
|
|
103
102
|
"@typescript-eslint/parser": "^5.35.1",
|
|
104
103
|
"commitizen": "^4.2.5",
|
|
104
|
+
"cpx": "^1.5.0",
|
|
105
105
|
"cz-conventional-changelog": "^3.3.0",
|
|
106
106
|
"eslint": "^8.23.0",
|
|
107
107
|
"eslint-config-prettier": "^8.5.0",
|
|
@@ -109,6 +109,7 @@
|
|
|
109
109
|
"eslint-plugin-prettier": "^4.2.1",
|
|
110
110
|
"husky": "^8.0.1",
|
|
111
111
|
"lint-staged": "^12.5.0",
|
|
112
|
+
"npm-run-all": "^4.1.5",
|
|
112
113
|
"rimraf": "^3.0.2",
|
|
113
114
|
"semantic-release": "^19.0.5",
|
|
114
115
|
"ts-node": "^10.9.1",
|
|
@@ -118,11 +119,6 @@
|
|
|
118
119
|
"peerDependencies": {
|
|
119
120
|
"typescript": "^4.7"
|
|
120
121
|
},
|
|
121
|
-
"config": {
|
|
122
|
-
"commitizen": {
|
|
123
|
-
"path": "cz-conventional-changelog"
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
122
|
"engines": {
|
|
127
123
|
"node": ">=14.0.0"
|
|
128
124
|
},
|
|
@@ -141,5 +137,11 @@
|
|
|
141
137
|
"homepage": "https://github.com/sanity-io/pkg-utils#readme",
|
|
142
138
|
"publishConfig": {
|
|
143
139
|
"access": "public"
|
|
140
|
+
},
|
|
141
|
+
"packageManager": "pnpm@7.12.2",
|
|
142
|
+
"pnpm": {
|
|
143
|
+
"overrides": {
|
|
144
|
+
"@sanity/pkg-utils": "workspace:*"
|
|
145
|
+
}
|
|
144
146
|
}
|
|
145
147
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** @internal */
|
|
2
|
+
export const _MODULE_EXT: Record<'commonjs' | 'module', {commonjs: string; esm: string}> = {
|
|
3
|
+
// "type": "commonjs"
|
|
4
|
+
commonjs: {
|
|
5
|
+
commonjs: '.js',
|
|
6
|
+
esm: '.mjs',
|
|
7
|
+
},
|
|
8
|
+
// "type": "module"
|
|
9
|
+
module: {
|
|
10
|
+
commonjs: '.cjs',
|
|
11
|
+
esm: '.js',
|
|
12
|
+
},
|
|
13
|
+
}
|
package/src/node/_core/index.ts
CHANGED
|
@@ -51,26 +51,51 @@ export function _printPackageTree(ctx: _BuildContext): void {
|
|
|
51
51
|
Object.entries(exports)
|
|
52
52
|
.filter(([, entry]) => entry._exported)
|
|
53
53
|
.map(([exportPath, entry]) => {
|
|
54
|
-
const exp: Omit<PkgExport, '_exported'> = {
|
|
54
|
+
const exp: Omit<PkgExport, '_exported'> = {
|
|
55
|
+
source: entry.source,
|
|
56
|
+
types: undefined,
|
|
57
|
+
browser: undefined,
|
|
58
|
+
node: undefined,
|
|
59
|
+
import: undefined,
|
|
60
|
+
require: undefined,
|
|
61
|
+
default: entry.default,
|
|
62
|
+
}
|
|
55
63
|
|
|
56
|
-
if (entry.types)
|
|
64
|
+
if (entry.types) {
|
|
65
|
+
exp.types = _fileInfo(entry.types)
|
|
66
|
+
} else {
|
|
67
|
+
delete exp.types
|
|
68
|
+
}
|
|
57
69
|
|
|
58
70
|
if (entry.browser) {
|
|
59
71
|
exp.browser = {source: entry.browser.source}
|
|
60
72
|
|
|
61
73
|
if (entry.browser.import) exp.browser.import = _fileInfo(entry.browser.import)
|
|
62
|
-
if (entry.browser.require) exp.browser.
|
|
74
|
+
if (entry.browser.require) exp.browser.require = _fileInfo(entry.browser.require)
|
|
75
|
+
} else {
|
|
76
|
+
delete exp.browser
|
|
63
77
|
}
|
|
64
78
|
|
|
65
79
|
if (entry.node) {
|
|
66
80
|
exp.node = {source: entry.node.source}
|
|
67
81
|
|
|
68
82
|
if (entry.node.import) exp.node.import = _fileInfo(entry.node.import)
|
|
69
|
-
if (entry.node.require) exp.node.
|
|
83
|
+
if (entry.node.require) exp.node.require = _fileInfo(entry.node.require)
|
|
84
|
+
} else {
|
|
85
|
+
delete exp.node
|
|
70
86
|
}
|
|
71
87
|
|
|
72
|
-
if (entry.import)
|
|
73
|
-
|
|
88
|
+
if (entry.import) {
|
|
89
|
+
exp.import = _fileInfo(entry.import)
|
|
90
|
+
} else {
|
|
91
|
+
delete exp.import
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (entry.require) {
|
|
95
|
+
exp.require = _fileInfo(entry.require)
|
|
96
|
+
} else {
|
|
97
|
+
delete exp.require
|
|
98
|
+
}
|
|
74
99
|
|
|
75
100
|
exp.default = _fileInfo(entry.default)
|
|
76
101
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import path from 'path'
|
|
3
|
-
import {PkgExport, PkgFormat, PkgRuntime, _BuildContext} from './_core'
|
|
3
|
+
import {PkgExport, PkgFormat, PkgRuntime, _BuildContext, _MODULE_EXT} from './_core'
|
|
4
4
|
import {_BuildTask, _DtsTask, _RollupTask, _RollupTaskEntry} from './_tasks'
|
|
5
5
|
|
|
6
6
|
/** @internal */
|
|
@@ -113,6 +113,7 @@ export function _resolveBuildTasks(ctx: _BuildContext): _BuildTask[] {
|
|
|
113
113
|
for (const exp of exports) {
|
|
114
114
|
if (exp._exported && exp._path !== '.') {
|
|
115
115
|
const relativeTargetPath = (exp.browser?.import || exp.import || '').replace(/\.[^/.]+$/, '')
|
|
116
|
+
const ext = _MODULE_EXT[pkg.type].esm
|
|
116
117
|
|
|
117
118
|
if (relativeTargetPath) {
|
|
118
119
|
fs.writeFileSync(
|
|
@@ -121,7 +122,7 @@ export function _resolveBuildTasks(ctx: _BuildContext): _BuildTask[] {
|
|
|
121
122
|
`// AUTO-GENERATED – DO NOT EDIT`,
|
|
122
123
|
``,
|
|
123
124
|
// `export {default} from '${relativeTargetPath}'`,
|
|
124
|
-
`export * from '${relativeTargetPath}'`,
|
|
125
|
+
`export * from '${relativeTargetPath}${pkg.type === 'commonjs' ? ext : ''}'`,
|
|
125
126
|
``,
|
|
126
127
|
].join('\n')
|
|
127
128
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import path from 'path'
|
|
3
|
-
import {PkgExport, PkgFormat, PkgRuntime, _BuildContext} from './_core'
|
|
3
|
+
import {PkgExport, PkgFormat, PkgRuntime, _BuildContext, _MODULE_EXT} from './_core'
|
|
4
4
|
import {_WatchTask, _DtsWatchTask, _RollupWatchTask, _RollupTaskEntry} from './_tasks'
|
|
5
5
|
|
|
6
6
|
/** @internal */
|
|
@@ -112,6 +112,7 @@ export function _resolveWatchTasks(ctx: _BuildContext): _WatchTask[] {
|
|
|
112
112
|
for (const exp of exports) {
|
|
113
113
|
if (exp._exported && exp._path !== '.') {
|
|
114
114
|
const relativeTargetPath = (exp.browser?.import || exp.import || '').replace(/\.[^/.]+$/, '')
|
|
115
|
+
const ext = _MODULE_EXT[pkg.type].esm
|
|
115
116
|
|
|
116
117
|
if (relativeTargetPath) {
|
|
117
118
|
fs.writeFileSync(
|
|
@@ -120,7 +121,7 @@ export function _resolveWatchTasks(ctx: _BuildContext): _WatchTask[] {
|
|
|
120
121
|
`// AUTO-GENERATED – DO NOT EDIT`,
|
|
121
122
|
``,
|
|
122
123
|
// `export {default} from '${relativeTargetPath}'`,
|
|
123
|
-
`export * from '${relativeTargetPath}'`,
|
|
124
|
+
`export * from '${relativeTargetPath}${pkg.type === 'commonjs' ? ext : ''}'`,
|
|
124
125
|
``,
|
|
125
126
|
].join('\n')
|
|
126
127
|
)
|
|
@@ -31,6 +31,7 @@ export async function _buildTypes(options: {
|
|
|
31
31
|
|
|
32
32
|
const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics)
|
|
33
33
|
|
|
34
|
+
// TODO: improve logging
|
|
34
35
|
allDiagnostics.forEach((diagnostic) => {
|
|
35
36
|
if (diagnostic.file && diagnostic.start) {
|
|
36
37
|
const {line, character} = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start)
|
|
@@ -6,11 +6,19 @@ export function _createApiExtractorConfig(options: {
|
|
|
6
6
|
exportPath: string
|
|
7
7
|
filePath: string
|
|
8
8
|
messages: IExtractorMessagesConfig
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
projectFolder: string
|
|
10
|
+
mainEntryPointFilePath: string
|
|
11
11
|
tsconfigPath: string
|
|
12
12
|
}): IConfigFile {
|
|
13
|
-
const {
|
|
13
|
+
const {
|
|
14
|
+
distPath,
|
|
15
|
+
exportPath,
|
|
16
|
+
filePath,
|
|
17
|
+
messages,
|
|
18
|
+
projectFolder,
|
|
19
|
+
mainEntryPointFilePath,
|
|
20
|
+
tsconfigPath,
|
|
21
|
+
} = options
|
|
14
22
|
|
|
15
23
|
return {
|
|
16
24
|
apiReport: {
|
|
@@ -35,7 +43,7 @@ export function _createApiExtractorConfig(options: {
|
|
|
35
43
|
enabled: false,
|
|
36
44
|
},
|
|
37
45
|
messages,
|
|
38
|
-
mainEntryPointFilePath
|
|
39
|
-
projectFolder
|
|
46
|
+
mainEntryPointFilePath,
|
|
47
|
+
projectFolder,
|
|
40
48
|
}
|
|
41
49
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {rename} from 'fs/promises'
|
|
2
1
|
import path from 'path'
|
|
3
2
|
import {promisify} from 'util'
|
|
4
3
|
import {ExtractorMessage} from '@microsoft/api-extractor'
|
|
5
|
-
import cpx from 'cpx'
|
|
6
4
|
import rimrafCallback from 'rimraf'
|
|
7
5
|
import {_BuildContext} from '../../_core'
|
|
8
6
|
import {_buildTypes} from './_buildTypes'
|
|
@@ -12,25 +10,30 @@ import {_DtsResult, _DtsTask, _DtsWatchTask} from './_types'
|
|
|
12
10
|
|
|
13
11
|
const rimraf = promisify(rimrafCallback)
|
|
14
12
|
|
|
13
|
+
/**
|
|
14
|
+
* - Build type definitions to a temporary directory using TypeScript compiler.
|
|
15
|
+
* - Create a type definition bundle for each export entry.
|
|
16
|
+
* - When done, remove the temporary directory.
|
|
17
|
+
*/
|
|
15
18
|
export async function _doExtract(
|
|
16
19
|
ctx: _BuildContext,
|
|
17
20
|
task: _DtsTask | _DtsWatchTask
|
|
18
21
|
): Promise<_DtsResult> {
|
|
19
|
-
const {config, cwd,
|
|
22
|
+
const {config, cwd, files, ts} = ctx
|
|
20
23
|
|
|
21
24
|
if (!ts.config || !ts.configPath) {
|
|
22
25
|
return {type: 'dts', messages: [], results: []}
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
const
|
|
28
|
+
const {outDir, rootDir = cwd} = ts.config.options
|
|
26
29
|
|
|
27
|
-
|
|
30
|
+
if (!outDir) {
|
|
31
|
+
throw new Error('tsconfig.json is missing `compilerOptions.outDir`')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const tmpPath = path.resolve(outDir, '__tmp__')
|
|
28
35
|
|
|
29
|
-
await _buildTypes({
|
|
30
|
-
cwd,
|
|
31
|
-
outDir: outDir,
|
|
32
|
-
tsconfig: ts.config,
|
|
33
|
-
})
|
|
36
|
+
await _buildTypes({cwd, outDir: tmpPath, tsconfig: ts.config})
|
|
34
37
|
|
|
35
38
|
const messages: ExtractorMessage[] = []
|
|
36
39
|
|
|
@@ -39,48 +42,34 @@ export async function _doExtract(
|
|
|
39
42
|
for (const entry of task.entries) {
|
|
40
43
|
const exportPath = entry.exportPath === '.' ? './index' : entry.exportPath
|
|
41
44
|
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
path.relative(cwd,
|
|
45
|
-
entry.sourcePath.replace(/\.ts$/, '.d.ts')
|
|
45
|
+
const sourceTypesPath = path.resolve(
|
|
46
|
+
tmpPath,
|
|
47
|
+
path.relative(rootDir, path.resolve(cwd, entry.sourcePath)).replace(/\.ts$/, '.d.ts')
|
|
46
48
|
)
|
|
47
49
|
|
|
48
|
-
const
|
|
50
|
+
const targetPath = path.resolve(cwd, entry.targetPath)
|
|
49
51
|
|
|
50
52
|
const result = await _extractTypes({
|
|
51
53
|
cwd,
|
|
52
54
|
exportPath,
|
|
53
55
|
files,
|
|
54
|
-
filePath,
|
|
56
|
+
filePath: path.relative(outDir, targetPath),
|
|
55
57
|
projectPath: cwd,
|
|
56
58
|
rules: config?.extract?.rules,
|
|
57
|
-
|
|
58
|
-
tsconfigPath: path.resolve(cwd, ts.configPath),
|
|
59
|
-
distPath,
|
|
59
|
+
sourceTypesPath: sourceTypesPath,
|
|
60
|
+
tsconfigPath: path.resolve(cwd, ts.configPath || 'tsconfig.json'),
|
|
61
|
+
distPath: outDir,
|
|
60
62
|
})
|
|
61
63
|
|
|
62
|
-
results.push({sourcePath, filePath})
|
|
63
|
-
|
|
64
64
|
messages.push(...result.messages)
|
|
65
65
|
|
|
66
66
|
if (result.messages.some((msg) => msg.logLevel === 'error')) {
|
|
67
|
+
await rimraf(tmpPath)
|
|
68
|
+
|
|
67
69
|
throw new _DtsError('encountered errors when extracting types', result.messages)
|
|
68
70
|
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const tmpPath = path.resolve(distPath, '__tmp__')
|
|
72
|
-
|
|
73
|
-
await rename(outDir, tmpPath)
|
|
74
|
-
|
|
75
|
-
for (const result of results) {
|
|
76
|
-
const fromPath = path.resolve(
|
|
77
|
-
tmpPath,
|
|
78
|
-
path.relative(outDir, path.resolve(distPath, result.filePath))
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
const toPath = path.resolve(distPath, result.filePath)
|
|
82
71
|
|
|
83
|
-
|
|
72
|
+
results.push({sourcePath: path.resolve(cwd, entry.sourcePath), filePath: targetPath})
|
|
84
73
|
}
|
|
85
74
|
|
|
86
75
|
await rimraf(tmpPath)
|
|
@@ -29,10 +29,10 @@ export async function _extractTypes(options: {
|
|
|
29
29
|
files: _BuildFile[]
|
|
30
30
|
projectPath: string
|
|
31
31
|
rules?: NonNullable<PkgConfigOptions['extract']>['rules']
|
|
32
|
-
|
|
32
|
+
sourceTypesPath: string
|
|
33
33
|
tsconfigPath: string
|
|
34
34
|
}): Promise<{extractorResult: ExtractorResult; messages: ExtractorMessage[]}> {
|
|
35
|
-
const {distPath, exportPath, files, filePath, projectPath, rules,
|
|
35
|
+
const {distPath, exportPath, files, filePath, projectPath, rules, sourceTypesPath, tsconfigPath} =
|
|
36
36
|
options
|
|
37
37
|
|
|
38
38
|
const tsdocConfigFile = await _createTSDocConfig({
|
|
@@ -116,8 +116,8 @@ export async function _extractTypes(options: {
|
|
|
116
116
|
exportPath,
|
|
117
117
|
filePath,
|
|
118
118
|
messages: messagesConfig,
|
|
119
|
-
projectPath,
|
|
120
|
-
|
|
119
|
+
projectFolder: projectPath,
|
|
120
|
+
mainEntryPointFilePath: sourceTypesPath,
|
|
121
121
|
tsconfigPath,
|
|
122
122
|
}),
|
|
123
123
|
configObjectFullPath: undefined,
|
|
@@ -8,7 +8,7 @@ import replace from '@rollup/plugin-replace'
|
|
|
8
8
|
import {InputOptions, OutputOptions} from 'rollup'
|
|
9
9
|
import esbuild from 'rollup-plugin-esbuild'
|
|
10
10
|
import {terser} from 'rollup-plugin-terser'
|
|
11
|
-
import {_BuildContext, _DEFAULTS} from '../../_core'
|
|
11
|
+
import {_BuildContext, _DEFAULTS, _MODULE_EXT} from '../../_core'
|
|
12
12
|
import {_RollupTask, _RollupWatchTask} from '../_types'
|
|
13
13
|
|
|
14
14
|
export interface _RollupConfig {
|
|
@@ -23,7 +23,8 @@ export function _resolveRollupConfig(
|
|
|
23
23
|
): _RollupConfig {
|
|
24
24
|
const {format, runtime, target} = buildTask
|
|
25
25
|
const {config, cwd, exports: _exports, external, dist: outDir, logger, pkg, ts} = ctx
|
|
26
|
-
const outputExt = format
|
|
26
|
+
const outputExt = _MODULE_EXT[pkg.type][format]
|
|
27
|
+
|
|
27
28
|
const minify = config?.minify ?? true
|
|
28
29
|
|
|
29
30
|
const pathAliases = Object.fromEntries(
|
package/src/node/watch.ts
CHANGED
|
@@ -33,7 +33,7 @@ export async function watch(options: {cwd: string; tsconfig?: string}): Promise<
|
|
|
33
33
|
const watchTasks = _resolveWatchTasks(ctx)
|
|
34
34
|
|
|
35
35
|
for (const task of watchTasks) {
|
|
36
|
-
const handler = _watchTaskHandlers[task.type] as _TaskHandler<_WatchTask,
|
|
36
|
+
const handler = _watchTaskHandlers[task.type] as _TaskHandler<_WatchTask, unknown>
|
|
37
37
|
const result$ = handler.exec(ctx, task)
|
|
38
38
|
|
|
39
39
|
result$.subscribe({
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_build-0377061e.cjs","sources":["../src/node/_resolveBuildTasks.ts","../src/node/_spinner.ts","../src/node/build.ts"],"sourcesContent":["import fs from 'fs'\nimport path from 'path'\nimport {PkgExport, PkgFormat, PkgRuntime, _BuildContext} from './_core'\nimport {_BuildTask, _DtsTask, _RollupTask, _RollupTaskEntry} from './_tasks'\n\n/** @internal */\nexport function _resolveBuildTasks(ctx: _BuildContext): _BuildTask[] {\n const {cwd, pkg, target} = ctx\n\n const tasks: _BuildTask[] = []\n\n const exports = Object.entries(ctx.exports || {}).map(\n ([_path, exp]) => ({_path, ...exp} as PkgExport & {_path: string})\n )\n\n const dtsTask: _DtsTask = {\n type: 'build:dts',\n entries: [],\n }\n\n const rollupTasks: Record<string, _RollupTask> = {}\n\n function _addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: _RollupTaskEntry) {\n const buildId = `${format}:${runtime}`\n\n if (rollupTasks[buildId]) {\n rollupTasks[buildId].entries.push(entry)\n } else {\n rollupTasks[buildId] = {\n type: 'build:js',\n buildId,\n entries: [entry],\n runtime,\n format,\n target: target[runtime],\n }\n }\n }\n\n // Parse `dts` tasks\n for (const exp of exports) {\n const importId = path.join(pkg.name, exp._path)\n\n if (exp.types) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.source,\n targetPath: exp.types,\n })\n }\n }\n\n // Parse rollup:commonjs:* tasks\n for (const exp of exports) {\n const output = exp.require\n\n if (!output) continue\n\n _addRollupTaskEntry('commonjs', ctx.runtime, {\n path: exp._path,\n source: exp.source,\n output,\n })\n }\n\n // Parse rollup:commonjs:browser tasks\n for (const exp of exports) {\n const output = exp.browser?.require\n\n if (!output) continue\n\n _addRollupTaskEntry('commonjs', 'browser', {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:* tasks\n for (const exp of exports) {\n const output = exp.import\n\n if (!output) continue\n\n _addRollupTaskEntry('esm', ctx.runtime, {\n path: exp._path,\n source: exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:browser tasks\n for (const exp of exports) {\n const output = exp.browser?.import\n\n if (!output) continue\n\n _addRollupTaskEntry('esm', 'browser', {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output,\n })\n }\n\n if (dtsTask.entries.length) {\n tasks.push(dtsTask)\n }\n\n tasks.push(...Object.values(rollupTasks))\n\n // Parse rollup:esm:browser tasks\n for (const exp of exports) {\n if (exp._exported && exp._path !== '.') {\n const relativeTargetPath = (exp.browser?.import || exp.import || '').replace(/\\.[^/.]+$/, '')\n\n if (relativeTargetPath) {\n fs.writeFileSync(\n path.resolve(cwd, `${exp._path}.js`),\n [\n `// AUTO-GENERATED – DO NOT EDIT`,\n ``,\n // `export {default} from '${relativeTargetPath}'`,\n `export * from '${relativeTargetPath}'`,\n ``,\n ].join('\\n')\n )\n }\n }\n }\n\n return tasks\n}\n","/* eslint-disable no-console */\n\nimport chalk from 'chalk'\n\nexport function _spinner(msg: string): {complete: () => void; error: () => void} {\n const startTime = Date.now()\n\n console.log(`${chalk.yellow('run ')} ${msg}`)\n\n return {\n complete: () => {\n console.log(`${chalk.green('ok ')} ${chalk.gray(`${Date.now() - startTime}ms`)}`)\n },\n error: () => {\n console.log(`${chalk.red(`failed`)} ${chalk.gray(`${Date.now() - startTime}ms`)}`)\n },\n }\n}\n","import {_loadConfig, _loadPkgWithReporting} from './_core'\nimport {_resolveBuildContext} from './_resolveBuildContext'\nimport {_resolveBuildTasks} from './_resolveBuildTasks'\nimport {_spinner} from './_spinner'\nimport {_BuildTask, _TaskHandler, _buildTaskHandlers} from './_tasks'\n\n/** @public */\nexport async function build(options: {cwd: string; tsconfig?: string}): Promise<void> {\n const {cwd, tsconfig = 'tsconfig.json'} = options\n\n const pkg = await _loadPkgWithReporting({cwd})\n const config = await _loadConfig({cwd})\n\n const ctx = await _resolveBuildContext({config, cwd, pkg, tsconfig})\n\n const buildTasks = _resolveBuildTasks(ctx)\n\n for (const task of buildTasks) {\n const handler = _buildTaskHandlers[task.type] as _TaskHandler<_BuildTask>\n const taskName = handler.name(ctx, task)\n\n const spinner = _spinner(taskName)\n\n try {\n const result = await handler.exec(ctx, task).toPromise()\n\n spinner.complete()\n ctx.logger.log()\n\n handler.complete(ctx, task, result)\n } catch (err) {\n spinner.error()\n\n if (err instanceof Error) {\n const RE_CWD = new RegExp(`${cwd}`, 'g')\n\n ctx.logger.error(err.message.replace(RE_CWD, '.'))\n ctx.logger.log()\n }\n\n handler.error(ctx, task, err)\n\n process.exit(1)\n }\n }\n}\n"],"names":["_resolveBuildTasks","ctx","_a","_b","_c","_d","_e","cwd","pkg","target","tasks","exports","Object","entries","map","_path","exp","dtsTask","type","rollupTasks","_addRollupTaskEntry","format","runtime","entry","buildId","push","importId","path","join","name","types","exportPath","sourcePath","source","targetPath","output","require","browser","import","length","values","_exported","relativeTargetPath","replace","fs","writeFileSync","resolve","_spinner","msg","startTime","Date","now","console","log","chalk","yellow","complete","green","gray","error","red","build","options","tsconfig","_loadPkgWithReporting","config","_loadConfig","_resolveBuildContext","buildTasks","task","handler","_buildTaskHandlers","taskName","spinner","result","exec","toPromise","logger","err","Error","RE_CWD","RegExp","message","process","exit"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEO,SAASA,kBAAT,CAA4BC,GAA5B,EAAiC;EACtC,IAAIC,EAAJ,EAAQC,EAAR,EAAYC,EAAZ,EAAgBC,EAAhB,EAAoBC,EAApB;;EACA,MAAM;IAAEC,GAAF;IAAOC,GAAP;IAAYC;EAAZ,IAAuBR,GAA7B;EACA,MAAMS,KAAK,GAAG,EAAd;EACA,MAAMC,OAAO,GAAGC,MAAM,CAACC,OAAP,CAAeZ,GAAG,CAACU,OAAJ,IAAe,EAA9B,EAAkCG,GAAlC,CACd;IAAA,IAAC,CAACC,KAAD,EAAQC,GAAR,CAAD;IAAA;MAAqBD;IAArB,GAA+BC,GAA/B;EAAA,CADc,CAAhB;EAGA,MAAMC,OAAO,GAAG;IACdC,IAAI,EAAE,WADQ;IAEd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B,QAAR;MACAvD,GAAG,CAAC4E,MAAJ,CAAWxB,GAAX;MACAiB,OAAO,CAACd,QAAR,CAAiBvD,GAAjB,EAAsBoE,IAAtB,EAA4BK,MAA5B;IACD,CALD,CAKE,OAAOI,GAAP,EAAY;MACZL,OAAO,CAACd,KAAR;;MACA,IAAImB,GAAG,YAAYC,KAAnB,EAA0B;QACxB,MAAMC,MAAM,GAAG,IAAIC,MAAJ,WAAc1E,GAAd,GAAqB,GAArB,CAAf;QACAN,GAAG,CAAC4E,MAAJ,CAAWlB,KAAX,CAAiBmB,GAAG,CAACI,OAAJ,CAAYvC,OAAZ,CAAoBqC,MAApB,EAA4B,GAA5B,CAAjB;QACA/E,GAAG,CAAC4E,MAAJ,CAAWxB,GAAX;MACD;;MACDiB,OAAO,CAACX,KAAR,CAAc1D,GAAd,EAAmBoE,IAAnB,EAAyBS,GAAzB;MACAK,OAAO,CAACC,IAAR,CAAa,CAAb;IACD;EACF;AACH;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_check-11811a4d.cjs","sources":["../src/node/_getFilesize.ts","../src/node/_printPackageTree.ts","../src/node/check.ts"],"sourcesContent":["import {statSync} from 'fs'\nimport prettyBytes from 'pretty-bytes'\n\nexport function _getFilesize(file: string): string {\n const stats = statSync(file)\n\n return prettyBytes(stats.size)\n}\n","import fs from 'fs'\nimport path from 'path'\nimport chalk from 'chalk'\nimport treeify from 'treeify'\nimport {PkgExport, _BuildContext} from './_core'\nimport {_getFilesize} from './_getFilesize'\n\nexport function _fileExists(file: string): boolean {\n try {\n fs.accessSync(file)\n\n return true\n } catch (_) {\n return false\n }\n}\n\nfunction _getFileInfo(cwd: string, filePath: string) {\n const p = path.resolve(cwd, filePath)\n const exists = _fileExists(p)\n const size = exists ? _getFilesize(p) : undefined\n\n return {exists, size}\n}\n\nexport function _printPackageTree(ctx: _BuildContext): void {\n const {cwd, exports, logger, pkg} = ctx\n\n if (!exports) return\n\n logger.log(`${chalk.blue(pkg.name)}@${chalk.green(pkg.version)}`)\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const tree: Record<string, any> = {}\n\n if (pkg.bin) {\n tree.bin = pkg.bin\n }\n\n function _fileInfo(file: string) {\n const info = _getFileInfo(cwd, file)\n\n if (!info.size) {\n return `${chalk.gray(file)} ${chalk.red('does not exist')}`\n }\n\n return `${file} ${chalk.gray(info.size)}`\n }\n\n tree.exports = Object.fromEntries(\n Object.entries(exports)\n .filter(([, entry]) => entry._exported)\n .map(([exportPath, entry]) => {\n const exp: Omit<PkgExport, '_exported'> = {source: entry.source, default: entry.default}\n\n if (entry.types) exp.types = _fileInfo(entry.types)\n\n if (entry.browser) {\n exp.browser = {source: entry.browser.source}\n\n if (entry.browser.import) exp.browser.import = _fileInfo(entry.browser.import)\n if (entry.browser.require) exp.browser.import = _fileInfo(entry.browser.require)\n }\n\n if (entry.node) {\n exp.node = {source: entry.node.source}\n\n if (entry.node.import) exp.node.import = _fileInfo(entry.node.import)\n if (entry.node.require) exp.node.import = _fileInfo(entry.node.require)\n }\n\n if (entry.import) exp.import = _fileInfo(entry.import)\n if (entry.require) exp.require = _fileInfo(entry.require)\n\n exp.default = _fileInfo(entry.default)\n\n return [chalk.green(path.join(pkg.name, exportPath)), exp]\n })\n )\n\n logger.log(treeify.asTree(tree, true, true))\n}\n","/* eslint-disable no-console */\n\nimport path from 'path'\nimport chalk from 'chalk'\nimport esbuild, {BuildFailure} from 'esbuild'\nimport {_loadConfig, _loadPkgWithReporting} from './_core'\nimport {_fileExists, _printPackageTree} from './_printPackageTree'\nimport {_resolveBuildContext} from './_resolveBuildContext'\n\n/** @public */\nexport async function check(options: {\n cwd: string\n strict?: boolean\n tsconfig?: string\n}): Promise<void> {\n const {cwd, strict, tsconfig = 'tsconfig.json'} = options\n\n const pkg = await _loadPkgWithReporting({cwd})\n const config = await _loadConfig({cwd})\n const ctx = await _resolveBuildContext({config, cwd, pkg, tsconfig})\n\n _printPackageTree(ctx)\n\n if (strict) {\n const missingFiles: string[] = []\n\n // Check if there are missing files\n for (const [, exp] of Object.entries(ctx.exports || {})) {\n if (exp.source && !_fileExists(path.resolve(cwd, exp.source))) {\n missingFiles.push(exp.source)\n }\n\n if (exp.require && !_fileExists(path.resolve(cwd, exp.require))) {\n missingFiles.push(exp.require)\n }\n\n if (exp.import && !_fileExists(path.resolve(cwd, exp.import))) {\n missingFiles.push(exp.import)\n }\n\n if (exp.types && !_fileExists(path.resolve(cwd, exp.types))) {\n missingFiles.push(exp.types)\n }\n }\n\n if (missingFiles.length) {\n throw new Error('missing files')\n }\n\n // Check if the files are resolved\n const _paths: {require: string[]; import: string[]} = {\n require: [],\n import: [],\n }\n\n for (const [exportPath, exp] of Object.entries(ctx.exports || {})) {\n if (!exp._exported) continue\n if (exp.require) _paths.require.push(exportPath)\n if (exp.import) _paths.import.push(exportPath)\n }\n\n const external = Object.keys(pkg.dependencies || {}).concat(\n Object.keys(pkg.devDependencies || {})\n )\n\n if (_paths.import.length) {\n const code = _paths.import.map((id) => `import('${id}')`).join('\\n')\n\n try {\n const esbuildResult = await esbuild.build({\n external,\n stdin: {\n contents: code,\n loader: 'js',\n resolveDir: cwd,\n },\n format: 'esm',\n bundle: true,\n logLevel: 'silent',\n // otherwise output maps to stdout as we're using stdin\n outfile: '/dev/null',\n platform: 'node',\n })\n\n if (esbuildResult.warnings.length > 0) {\n console.warn(...esbuildResult.warnings)\n }\n } catch (err) {\n const {errors} = err as BuildFailure\n\n for (const _err of errors) {\n if (_err.location) {\n console.log(chalk.red('error'), _err.detail || _err.text)\n console.log(`${_err.location.line} | ${_err.location.lineText}`)\n console.log(\n 'in',\n `./${_err.location.file}:${_err.location.line}:${_err.location.column}`\n )\n } else {\n console.log(_err.detail || _err.text)\n }\n\n console.log()\n }\n\n process.exit(1)\n }\n }\n\n if (_paths.require.length) {\n const code = _paths.require.map((id) => `require('${id}')`).join('\\n')\n\n const esbuildResult = await esbuild.build({\n external,\n stdin: {\n contents: code,\n loader: 'js',\n resolveDir: cwd,\n },\n format: 'cjs',\n bundle: true,\n // otherwise output maps to stdout as we're using stdin\n outfile: '/dev/null',\n platform: 'node',\n })\n\n if (esbuildResult.errors.length > 0) {\n throw new Error(esbuildResult.errors.join(', '))\n }\n\n if (esbuildResult.warnings.length > 0) {\n console.warn(...esbuildResult.warnings)\n }\n }\n }\n}\n"],"names":["_getFilesize","file","stats","statSync","prettyBytes","size","_fileExists","fs","accessSync","_","_getFileInfo","cwd","filePath","p","path","resolve","exists","_printPackageTree","ctx","exports","logger","pkg","log","chalk","blue","name","green","version","tree","bin","_fileInfo","info","gray","red","Object","fromEntries","entries","filter","entry","_exported","map","exportPath","exp","source","default","types","browser","import","require","node","join","treeify","asTree","check","options","strict","tsconfig","_loadPkgWithReporting","config","_loadConfig","_resolveBuildContext","missingFiles","push","length","Error","_paths","external","keys","dependencies","concat","devDependencies","code","id","esbuildResult","esbuild","build","stdin","contents","loader","resolveDir","format","bundle","logLevel","outfile","platform","warnings","console","warn","err","errors","_err","location","detail","text","line","lineText","column","process","exit"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEO,SAASA,YAAT,CAAsBC,IAAtB,EAA4B;EACjC,MAAMC,KAAK,GAAGC,WAAAA,CAASF,IAATE,CAAd;EACA,OAAOC,oBAAW,CAAA,SAAA,CAAXA,CAAYF,KAAK,CAACG,IAAlBD,CAAP;AACF;;ACAO,SAASE,WAAT,CAAqBL,IAArB,EAA2B;EAChC,IAAI;IACFM,sBAAAA,CAAGC,UAAHD,CAAcN,IAAdM;IACA,OAAO,IAAP;EACD,CAHD,CAGE,OAAOE,CAAP,EAAU;IACV,OAAO,KAAP;EACD;AACF;;AACD,SAASC,YAAT,CAAsBC,GAAtB,EAA2BC,QAA3B,EAAqC;EACnC,MAAMC,CAAC,GAAGC,aAAI,CAAA,SAAA,CAAJA,CAAKC,OAALD,CAAaH,GAAbG,EAAkBF,QAAlBE,CAAV;;EACA,MAAME,MAAM,GA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