jiek 2.3.2 → 2.3.4
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/.internal/.chunks/{filterSupport.4rM7f6jB.cjs → getWD.Bdo2NGCR.cjs} +30 -30
- package/dist/.internal/.chunks/{filterSupport.BXWpLBpT.js → getWD.DGvwAHMY.js} +29 -29
- package/dist/.internal/.chunks/{loadConfig.OOKddvHF.cjs → loadConfig.8xhNFEJe.cjs} +30 -12
- package/dist/.internal/.chunks/{loadConfig.CFfzkm_p.js → loadConfig.BjzxLOdC.js} +26 -9
- package/dist/.internal/bin/common.cjs +92 -97
- package/dist/.internal/bin/common.d.cts +2 -0
- package/dist/.internal/bin/common.d.ts +2 -0
- package/dist/.internal/bin/common.js +93 -98
- package/dist/.internal/bin/parseArgv.cjs +2 -2
- package/dist/.internal/bin/parseArgv.js +2 -2
- package/dist/.internal/commands/utils/createAreaManagement.cjs +108 -0
- package/dist/.internal/commands/utils/createAreaManagement.d.cts +18 -0
- package/dist/.internal/commands/utils/createAreaManagement.d.ts +18 -0
- package/dist/.internal/commands/utils/createAreaManagement.js +106 -0
- package/dist/.internal/polyfill.cjs +13 -0
- package/dist/.internal/polyfill.d.cts +1 -0
- package/dist/.internal/polyfill.d.ts +1 -0
- package/dist/.internal/polyfill.js +11 -0
- package/dist/.internal/rollup/base.d.cts +27 -4
- package/dist/.internal/rollup/base.d.ts +27 -4
- package/dist/.internal/utils/filterSupport.cjs +1 -1
- package/dist/.internal/utils/filterSupport.js +2 -2
- package/dist/.internal/utils/loadConfig.cjs +3 -3
- package/dist/.internal/utils/loadConfig.d.cts +1 -0
- package/dist/.internal/utils/loadConfig.d.ts +1 -0
- package/dist/.internal/utils/loadConfig.js +4 -4
- package/dist/.internal/utils/pascalCase.cjs +5 -0
- package/dist/.internal/utils/pascalCase.d.cts +3 -0
- package/dist/.internal/utils/pascalCase.d.ts +3 -0
- package/dist/.internal/utils/pascalCase.js +3 -0
- package/dist/.internal/utils/reveal.cjs +9 -0
- package/dist/.internal/utils/reveal.d.cts +3 -0
- package/dist/.internal/utils/reveal.d.ts +3 -0
- package/dist/.internal/utils/reveal.js +7 -0
- package/dist/bin/index.cjs +101 -43
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/rollup/index.cjs +91 -31
- package/dist/rollup/index.js +90 -30
- package/package.json +6 -2
- package/src/bin/build.cts +0 -5
- package/src/bin/common.ts +0 -3
- package/src/bin/index.cts +0 -7
- package/src/bin/parseArgv.ts +0 -26
- package/src/bridge.ts +0 -46
- package/src/commands/base.ts +0 -18
- package/src/commands/build/analyzer.ts +0 -122
- package/src/commands/build/client/analyzer.tsx +0 -121
- package/src/commands/build/client/index.ts +0 -26
- package/src/commands/build.ts +0 -544
- package/src/commands/descriptions.ts +0 -17
- package/src/commands/meta.ts +0 -5
- package/src/commands/publish.ts +0 -628
- package/src/commands/utils/optionParser.ts +0 -4
- package/src/index.ts +0 -12
- package/src/inner.ts +0 -11
- package/src/rollup/base.ts +0 -151
- package/src/rollup/bundle-analyzer.ts +0 -62
- package/src/rollup/index.ts +0 -892
- package/src/rollup/plugins/create-require.ts +0 -23
- package/src/rollup/plugins/progress.ts +0 -26
- package/src/rollup/plugins/replace.ts +0 -96
- package/src/rollup/plugins/skip.ts +0 -21
- package/src/rollup/plugins/with-external.ts +0 -23
- package/src/rollup/utils/commonOptions.ts +0 -9
- package/src/rollup/utils/externalResolver.ts +0 -47
- package/src/rollup/utils/globalResolver.ts +0 -13
- package/src/rollup/utils/withMinify.ts +0 -18
- package/src/rollup-plugin-utils.ts +0 -32
- package/src/server.ts +0 -30
- package/src/utils/checkDependency.ts +0 -26
- package/src/utils/filterSupport.ts +0 -90
- package/src/utils/getInternalModuleName.ts +0 -5
- package/src/utils/getRoot.ts +0 -14
- package/src/utils/getWD.ts +0 -31
- package/src/utils/intersection.ts +0 -1
- package/src/utils/loadConfig.ts +0 -108
- package/src/utils/recursiveListFiles.ts +0 -13
- package/src/utils/resolveExports.ts +0 -165
- package/src/utils/ts.ts +0 -94
- package/src/utils/tsRegister.ts +0 -22
package/dist/bin/index.cjs
CHANGED
@@ -1,41 +1,25 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
require('#~/
|
4
|
-
var
|
3
|
+
require('#~/polyfill');
|
4
|
+
var node_child_process = require('node:child_process');
|
5
5
|
var fs = require('node:fs');
|
6
6
|
var path = require('node:path');
|
7
7
|
var process = require('node:process');
|
8
|
-
var
|
8
|
+
var cliProgress = require('cli-progress');
|
9
9
|
var commander = require('commander');
|
10
10
|
var detectIndent = require('detect-indent');
|
11
11
|
var jsoncParser = require('jsonc-parser');
|
12
|
+
var bumper = require('@jiek/utils/bumper');
|
13
|
+
var createAreaManagement = require('#~/commands/utils/createAreaManagement');
|
12
14
|
var filterSupport = require('#~/utils/filterSupport');
|
15
|
+
var getInternalModuleName = require('#~/utils/getInternalModuleName');
|
13
16
|
var loadConfig = require('#~/utils/loadConfig');
|
14
17
|
var resolveExports = require('#~/utils/resolveExports');
|
15
|
-
|
18
|
+
require('#~/bin/common');
|
16
19
|
var parseArgv = require('#~/bin/parseArgv');
|
17
20
|
|
18
21
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
19
22
|
|
20
|
-
function _interopNamespace(e) {
|
21
|
-
if (e && e.__esModule) return e;
|
22
|
-
var n = Object.create(null);
|
23
|
-
if (e) {
|
24
|
-
Object.keys(e).forEach(function (k) {
|
25
|
-
if (k !== 'default') {
|
26
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
27
|
-
Object.defineProperty(n, k, d.get ? d : {
|
28
|
-
enumerable: true,
|
29
|
-
get: function () { return e[k]; }
|
30
|
-
});
|
31
|
-
}
|
32
|
-
});
|
33
|
-
}
|
34
|
-
n.default = e;
|
35
|
-
return Object.freeze(n);
|
36
|
-
}
|
37
|
-
|
38
|
-
var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
|
39
23
|
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
40
24
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
41
25
|
var process__default = /*#__PURE__*/_interopDefault(process);
|
@@ -52,23 +36,31 @@ const description = `
|
|
52
36
|
Publish package to npm registry, and auto generate exports field and other fields in published package.json.
|
53
37
|
If you want to through the options to the \`pnpm publish\` command, you can pass the options after '--'.
|
54
38
|
`.trim();
|
55
|
-
async function forEachSelectedProjectsGraphEntries(callback) {
|
39
|
+
async function forEachSelectedProjectsGraphEntries(callback, selectedProjectsGraphEntriesCallback) {
|
56
40
|
const { value = {} } = await filterSupport.getSelectedProjectsGraph() ?? {};
|
57
41
|
const selectedProjectsGraphEntries = Object.entries(value);
|
58
42
|
if (selectedProjectsGraphEntries.length === 0) {
|
59
43
|
throw new Error("no packages selected");
|
60
44
|
}
|
61
|
-
|
62
|
-
|
63
|
-
|
45
|
+
await selectedProjectsGraphEntriesCallback?.(selectedProjectsGraphEntries);
|
46
|
+
const tasks = selectedProjectsGraphEntries.map(
|
47
|
+
async ([dir, manifest], index, entries) => callback(
|
48
|
+
dir,
|
49
|
+
manifest,
|
50
|
+
index,
|
51
|
+
entries
|
52
|
+
)
|
53
|
+
);
|
54
|
+
await Promise.all(tasks);
|
64
55
|
}
|
65
56
|
const attachPublishOptions = (command) => command.option("-b, --bumper <bumper>", "bump version", "patch").option("-no-b, --no-bumper", "no bump version").option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option("--skipJS", 'skip entries which end with ".js"');
|
66
57
|
attachPublishOptions(
|
67
58
|
commander.program.command("publish").description(description).aliases(["pub", "p"])
|
68
|
-
).action(async ({
|
59
|
+
).option("--no-parallel", "Disable parallel publish").action(async ({
|
69
60
|
outdir,
|
70
|
-
bumper
|
71
|
-
skipJS
|
61
|
+
bumper,
|
62
|
+
skipJS,
|
63
|
+
parallel
|
72
64
|
}) => {
|
73
65
|
let shouldPassThrough = false;
|
74
66
|
const passThroughOptions = process__default.default.argv.reduce(
|
@@ -83,23 +75,89 @@ attachPublishOptions(
|
|
83
75
|
},
|
84
76
|
[]
|
85
77
|
);
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
78
|
+
const mb = new cliProgress.MultiBar({
|
79
|
+
hideCursor: true,
|
80
|
+
format: "{message}"
|
81
|
+
});
|
82
|
+
const bars = {};
|
83
|
+
const outputLines = [];
|
84
|
+
function render() {
|
85
|
+
let i;
|
86
|
+
for (i = 0; i < outputLines.length; i++) {
|
87
|
+
let bar = bars[i];
|
88
|
+
if (!bar) {
|
89
|
+
bars[i] = bar = mb.create(0, 0, { message: "" });
|
90
|
+
}
|
91
|
+
bar.update({ message: outputLines[i] });
|
92
|
+
}
|
93
|
+
for (; i < Object.keys(bars).length; i++) {
|
94
|
+
mb.remove(bars[i]);
|
90
95
|
}
|
96
|
+
}
|
97
|
+
const areaManagement = parallel ? createAreaManagement.createAreaManagement({
|
98
|
+
maxSize: 5,
|
99
|
+
outputLines,
|
100
|
+
onAreaUpdate: render
|
101
|
+
}) : void 0;
|
102
|
+
await forEachSelectedProjectsGraphEntries(async (dir, { name }) => {
|
103
|
+
const relativePath = path__default.default.relative(process__default.default.cwd(), dir);
|
104
|
+
const config = loadConfig.loadConfig(dir);
|
105
|
+
const { parallel: genParallelConfig } = config.publish ?? {};
|
106
|
+
const args = ["pnpm", "publish"];
|
91
107
|
args.push(...passThroughOptions);
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
108
|
+
const env = {
|
109
|
+
...process__default.default.env,
|
110
|
+
JIEK_PUBLISH_OUTDIR: JSON.stringify(outdir),
|
111
|
+
JIEK_PUBLISH_BUMPER: JSON.stringify(bumper),
|
112
|
+
JIEK_PUBLISH_SKIP_JS: JSON.stringify(skipJS)
|
113
|
+
};
|
114
|
+
const tag = bumper === false || ["minor", "major", "patch"].includes(bumper) ? "latest" : bumper;
|
115
|
+
const parallelConfig = parallel ? genParallelConfig?.(tag) : {};
|
116
|
+
async function pubByPnpm(type, attachArgs = [], isReady = false) {
|
117
|
+
const area = areaManagement?.create({
|
118
|
+
header: `\u250C publishing [${name}${type ? `@${type}` : ""}] ./${relativePath}`,
|
119
|
+
footer: "\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"
|
120
|
+
});
|
121
|
+
const info = (message) => area?.info(
|
122
|
+
message.trim().split("\n").map((s) => `\u2502 ${s}`).join("\n")
|
123
|
+
);
|
124
|
+
area && info("waiting for ready...");
|
125
|
+
isReady && await isReady;
|
126
|
+
const child = node_child_process.exec(
|
127
|
+
[...args, ...attachArgs, "--tag", type ?? tag].join(" "),
|
128
|
+
{ cwd: dir, windowsHide: true, env }
|
129
|
+
);
|
130
|
+
try {
|
131
|
+
if (area) {
|
132
|
+
child.stdout?.on("data", (data) => info(data));
|
133
|
+
child.stderr?.on("data", (data) => info(data));
|
134
|
+
} else {
|
135
|
+
child.stdout?.pipe(process__default.default.stdout);
|
136
|
+
child.stderr?.pipe(process__default.default.stderr);
|
137
|
+
}
|
138
|
+
} finally {
|
139
|
+
await new Promise((resolve) => {
|
140
|
+
child.once("exit", (code) => {
|
141
|
+
if (code === 0) {
|
142
|
+
resolve();
|
143
|
+
} else {
|
144
|
+
info(`pnpm publish exited with code ${code}`);
|
145
|
+
resolve();
|
146
|
+
}
|
147
|
+
});
|
148
|
+
});
|
149
|
+
await area?.exit();
|
100
150
|
}
|
101
|
-
}
|
151
|
+
}
|
152
|
+
const buildEnd = Promise.withResolvers();
|
153
|
+
await Promise.all([
|
154
|
+
pubByPnpm().then(() => buildEnd.resolve()).catch((e) => buildEnd.reject(e)),
|
155
|
+
...Object.entries(parallelConfig ?? {}).map(async ([type]) => {
|
156
|
+
await pubByPnpm(type, ["--ignore-scripts"], buildEnd.promise);
|
157
|
+
})
|
158
|
+
]);
|
102
159
|
});
|
160
|
+
mb.stop();
|
103
161
|
});
|
104
162
|
async function prepublish({
|
105
163
|
bumper: bumper$1,
|
package/dist/index.d.cts
CHANGED
@@ -35,6 +35,12 @@ declare module 'jiek' {
|
|
35
35
|
* @default true
|
36
36
|
*/
|
37
37
|
withSource?: boolean;
|
38
|
+
parallel?: (tag: string) => false | void | null | Record<string, {
|
39
|
+
include?: string[];
|
40
|
+
overrideInclude?: string[];
|
41
|
+
exclude?: string[];
|
42
|
+
overrideExclude?: string[];
|
43
|
+
}>;
|
38
44
|
};
|
39
45
|
}
|
40
46
|
}
|
@@ -42,6 +48,7 @@ declare module 'jiek' {
|
|
42
48
|
interface ConfigExperimental {
|
43
49
|
}
|
44
50
|
interface Config {
|
51
|
+
extends?: string;
|
45
52
|
experimental?: ConfigExperimental;
|
46
53
|
}
|
47
54
|
declare const defineConfig: (config: Config) => Config;
|
package/dist/index.d.ts
CHANGED
@@ -35,6 +35,12 @@ declare module 'jiek' {
|
|
35
35
|
* @default true
|
36
36
|
*/
|
37
37
|
withSource?: boolean;
|
38
|
+
parallel?: (tag: string) => false | void | null | Record<string, {
|
39
|
+
include?: string[];
|
40
|
+
overrideInclude?: string[];
|
41
|
+
exclude?: string[];
|
42
|
+
overrideExclude?: string[];
|
43
|
+
}>;
|
38
44
|
};
|
39
45
|
}
|
40
46
|
}
|
@@ -42,6 +48,7 @@ declare module 'jiek' {
|
|
42
48
|
interface ConfigExperimental {
|
43
49
|
}
|
44
50
|
interface Config {
|
51
|
+
extends?: string;
|
45
52
|
experimental?: ConfigExperimental;
|
46
53
|
}
|
47
54
|
declare const defineConfig: (config: Config) => Config;
|
package/dist/rollup/index.cjs
CHANGED
@@ -1,23 +1,26 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
+
require('#~/polyfill');
|
3
4
|
var fs = require('node:fs');
|
4
5
|
var node_path = require('node:path');
|
5
6
|
var process = require('node:process');
|
6
|
-
var entrypoints = require('@jiek/pkger/entrypoints');
|
7
|
-
var rollupPluginDts = require('@jiek/rollup-plugin-dts');
|
8
|
-
var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
|
9
7
|
var commonjs = require('@rollup/plugin-commonjs');
|
10
8
|
var inject = require('@rollup/plugin-inject');
|
11
9
|
var json = require('@rollup/plugin-json');
|
12
10
|
var pluginNodeResolve = require('@rollup/plugin-node-resolve');
|
13
11
|
var ts$1 = require('typescript');
|
12
|
+
var entrypoints = require('@jiek/pkger/entrypoints');
|
13
|
+
var rollupPluginDts = require('@jiek/rollup-plugin-dts');
|
14
|
+
var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
|
14
15
|
var bridge = require('#~/bridge');
|
15
16
|
var bundleAnalyzer = require('#~/rollup/bundle-analyzer');
|
16
17
|
var getInternalModuleName = require('#~/utils/getInternalModuleName');
|
17
18
|
var intersection = require('#~/utils/intersection');
|
18
19
|
var loadConfig = require('#~/utils/loadConfig');
|
20
|
+
var pascalCase = require('#~/utils/pascalCase');
|
19
21
|
var recursiveListFiles = require('#~/utils/recursiveListFiles');
|
20
22
|
var resolveExports = require('#~/utils/resolveExports');
|
23
|
+
var reveal = require('#~/utils/reveal');
|
21
24
|
var ts = require('#~/utils/ts');
|
22
25
|
var rollupPluginUtils = require('jiek/rollup-plugin-utils');
|
23
26
|
var MagicString = require('magic-string');
|
@@ -65,6 +68,8 @@ var progress = (options = {}) => {
|
|
65
68
|
};
|
66
69
|
};
|
67
70
|
|
71
|
+
var require$1 = require;
|
72
|
+
|
68
73
|
var replace = rollupPluginUtils.definePlugin((options = {}) => {
|
69
74
|
const {
|
70
75
|
include = [/\.[cm]?[tj]sx?$/],
|
@@ -72,39 +77,99 @@ var replace = rollupPluginUtils.definePlugin((options = {}) => {
|
|
72
77
|
values = {},
|
73
78
|
sourcemap
|
74
79
|
} = options;
|
80
|
+
let { mode = "string" } = options;
|
75
81
|
const allValues = { ...values };
|
76
82
|
const allKeys = Object.keys(allValues);
|
77
83
|
const filter = rollupPluginUtils.createFilter({ include, exclude });
|
78
|
-
const replaceAll = (ctx, code) => {
|
84
|
+
const replaceAll = async (ctx, code) => {
|
79
85
|
const ms = new MagicString__default.default(code);
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
match.index + key.length,
|
89
|
-
typeof allValues[key] === "function" ? allValues[key]({
|
86
|
+
if (mode === "string") {
|
87
|
+
allKeys.forEach((key) => {
|
88
|
+
const reg = new RegExp(key, "g");
|
89
|
+
let match;
|
90
|
+
while (match = reg.exec(code)) {
|
91
|
+
const start = match.index;
|
92
|
+
const end = start + key.length;
|
93
|
+
const value = typeof allValues[key] === "function" ? allValues[key]({
|
90
94
|
...ctx,
|
91
95
|
code,
|
92
96
|
start,
|
93
|
-
end
|
94
|
-
|
95
|
-
|
97
|
+
end,
|
98
|
+
mode: "string"
|
99
|
+
}) : allValues[key];
|
100
|
+
if ([null, void 0, false].includes(value)) continue;
|
101
|
+
ms.overwrite(
|
102
|
+
match.index,
|
103
|
+
match.index + key.length,
|
104
|
+
value
|
105
|
+
);
|
106
|
+
}
|
107
|
+
});
|
108
|
+
} else if (mode === "ast-grep") {
|
109
|
+
const ext = node_path.extname(ctx.id);
|
110
|
+
const { parse, Lang } = await import('@ast-grep/napi');
|
111
|
+
let lang;
|
112
|
+
if (/[cm]?tsx?/.test(ext)) {
|
113
|
+
lang = Lang.TypeScript;
|
96
114
|
}
|
97
|
-
|
115
|
+
if (/[cm]?jsx?/.test(ext)) {
|
116
|
+
lang = Lang.JavaScript;
|
117
|
+
}
|
118
|
+
if (/json?/.test(ext)) {
|
119
|
+
lang = Lang.Json;
|
120
|
+
}
|
121
|
+
if (lang == null) return;
|
122
|
+
const root = parse(lang, code).root();
|
123
|
+
allKeys.forEach((key) => {
|
124
|
+
root.findAll(key).forEach((node) => {
|
125
|
+
const { start, end } = node.range();
|
126
|
+
let newValue = typeof allValues[key] === "function" ? allValues[key]({
|
127
|
+
...ctx,
|
128
|
+
code,
|
129
|
+
mode: "ast-grep",
|
130
|
+
node,
|
131
|
+
lang,
|
132
|
+
$: (input) => {
|
133
|
+
if (typeof input === "string") {
|
134
|
+
return node.getMatch(input)?.text();
|
135
|
+
}
|
136
|
+
if ("raw" in input) {
|
137
|
+
return node.getMatch(input.raw[0])?.text();
|
138
|
+
}
|
139
|
+
}
|
140
|
+
}) : allValues[key];
|
141
|
+
if ([null, void 0, false].includes(newValue)) return;
|
142
|
+
newValue = newValue.toString();
|
143
|
+
newValue = newValue.replace(/\$([a-z_\-]+)/gi, (_, [name]) => {
|
144
|
+
if (name == null) return _;
|
145
|
+
return node.getMatch(name)?.text() ?? _;
|
146
|
+
});
|
147
|
+
ms.overwrite(start.index, end.index, newValue);
|
148
|
+
});
|
149
|
+
});
|
150
|
+
}
|
98
151
|
return ms;
|
99
152
|
};
|
100
153
|
return {
|
101
154
|
name: "jiek:replace",
|
155
|
+
buildStart() {
|
156
|
+
if (mode === "ast-grep") {
|
157
|
+
try {
|
158
|
+
require$1.resolve("@ast-grep/napi");
|
159
|
+
this.warn(
|
160
|
+
"You are using `ast-grep` mode, please make sure you have installed `@ast-grep/napi`"
|
161
|
+
);
|
162
|
+
} catch {
|
163
|
+
mode = "string";
|
164
|
+
}
|
165
|
+
}
|
166
|
+
},
|
102
167
|
transform: {
|
103
168
|
order: "pre",
|
104
|
-
handler(code, id) {
|
169
|
+
async handler(code, id) {
|
105
170
|
if (allKeys.length === 0) return;
|
106
171
|
if (filter(id)) return;
|
107
|
-
const ms = replaceAll({ type: "transform", id }, code);
|
172
|
+
const ms = await replaceAll({ type: "transform", id }, code);
|
108
173
|
if (ms == null) return;
|
109
174
|
return {
|
110
175
|
code: ms.toString(),
|
@@ -114,10 +179,10 @@ var replace = rollupPluginUtils.definePlugin((options = {}) => {
|
|
114
179
|
},
|
115
180
|
renderChunk: {
|
116
181
|
order: "post",
|
117
|
-
handler(code, { fileName: id }) {
|
182
|
+
async handler(code, { fileName: id }) {
|
118
183
|
if (allKeys.length === 0) return;
|
119
184
|
if (filter(id)) return;
|
120
|
-
const ms = replaceAll({ type: "renderChunk", id }, code);
|
185
|
+
const ms = await replaceAll({ type: "renderChunk", id }, code);
|
121
186
|
if (ms == null) return;
|
122
187
|
return {
|
123
188
|
code: ms.toString(),
|
@@ -269,12 +334,6 @@ const resolveOutputControls = (context, output) => ({
|
|
269
334
|
dts: typeof output?.dts === "boolean" ? output.dts : typeof output?.dts === "function" ? output.dts(context) : true
|
270
335
|
});
|
271
336
|
const resolveWorkspacePath = (p) => node_path.resolve(WORKSPACE_ROOT, p);
|
272
|
-
const pascalCase = (str) => str.replace(/[@|/-](\w)/g, (_, $1) => $1.toUpperCase()).replace(/(?:^|-)(\w)/g, (_, $1) => $1.toUpperCase());
|
273
|
-
const reveal = (obj, keys) => keys.reduce((acc, key) => {
|
274
|
-
if (typeof acc === "string") throw new Error("key not found in exports");
|
275
|
-
if (!(key in acc)) throw new Error(`key ${key} not found in exports`);
|
276
|
-
return acc[key];
|
277
|
-
}, obj);
|
278
337
|
const resolveMinifyOptions = (minifyOptions) => typeof minifyOptions === "string" ? { type: minifyOptions } : minifyOptions ?? { type: "esbuild" };
|
279
338
|
const resolveBuilderOptions = (builder) => typeof builder === "string" ? { type: builder } : builder ?? { type: "esbuild" };
|
280
339
|
const resolvedMinifyOptions = resolveMinifyOptions(build.output?.minifyOptions ?? MINIFY_OPTIONS);
|
@@ -428,6 +487,7 @@ const generateConfigs = (context, {
|
|
428
487
|
const rollupOptions = [];
|
429
488
|
const commonPlugins = ({ sourcemap }) => [
|
430
489
|
replace({
|
490
|
+
...build.replacementsOptions,
|
431
491
|
sourcemap: sourcemap === "hidden" ? false : !!sourcemap,
|
432
492
|
values: build.replacements
|
433
493
|
}),
|
@@ -628,7 +688,7 @@ function template(packageJSON) {
|
|
628
688
|
imports: internalEntrypoints
|
629
689
|
} = packageJSON;
|
630
690
|
const pkgIsModule = type === "module";
|
631
|
-
const packageName = pascalCase(name);
|
691
|
+
const packageName = pascalCase.pascalCase(name);
|
632
692
|
const leafMap = /* @__PURE__ */ new Map();
|
633
693
|
const inputTags = /* @__PURE__ */ new Map();
|
634
694
|
const inputExports = /* @__PURE__ */ new Map();
|
@@ -723,8 +783,8 @@ function template(packageJSON) {
|
|
723
783
|
const exports = inputExports.get(input);
|
724
784
|
keysArr.forEach((keys) => {
|
725
785
|
const [path, ...conditionals] = keys;
|
726
|
-
const name2 = packageName + (path === "." ? "" : pascalCase(path));
|
727
|
-
const keyExports = reveal(exports, keys);
|
786
|
+
const name2 = packageName + (path === "." ? "" : pascalCase.pascalCase(path));
|
787
|
+
const keyExports = reveal.reveal(exports, keys);
|
728
788
|
const commonContext = {
|
729
789
|
path,
|
730
790
|
name: name2,
|
package/dist/rollup/index.js
CHANGED
@@ -1,25 +1,28 @@
|
|
1
|
+
import '#~/polyfill';
|
1
2
|
import fs from 'node:fs';
|
2
|
-
import { relative, resolve, dirname
|
3
|
+
import { extname, relative, resolve, dirname } from 'node:path';
|
3
4
|
import process from 'node:process';
|
4
|
-
import { getAllLeafs } from '@jiek/pkger/entrypoints';
|
5
|
-
import { dts } from '@jiek/rollup-plugin-dts';
|
6
|
-
import { getWorkspaceDir } from '@jiek/utils/getWorkspaceDir';
|
7
5
|
import commonjs from '@rollup/plugin-commonjs';
|
8
6
|
import inject from '@rollup/plugin-inject';
|
9
7
|
import json from '@rollup/plugin-json';
|
10
8
|
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
11
9
|
import ts from 'typescript';
|
10
|
+
import { getAllLeafs } from '@jiek/pkger/entrypoints';
|
11
|
+
import { dts } from '@jiek/rollup-plugin-dts';
|
12
|
+
import { getWorkspaceDir } from '@jiek/utils/getWorkspaceDir';
|
12
13
|
import { publish } from '#~/bridge';
|
13
14
|
import { bundleAnalyzer } from '#~/rollup/bundle-analyzer';
|
14
15
|
import { getInternalModuleName } from '#~/utils/getInternalModuleName';
|
15
16
|
import { intersection } from '#~/utils/intersection';
|
16
17
|
import { loadConfig } from '#~/utils/loadConfig';
|
18
|
+
import { pascalCase } from '#~/utils/pascalCase';
|
17
19
|
import { recursiveListFiles } from '#~/utils/recursiveListFiles';
|
18
20
|
import { getOutDirs, resolveExports } from '#~/utils/resolveExports';
|
21
|
+
import { reveal } from '#~/utils/reveal';
|
19
22
|
import { getCompilerOptionsByFilePath } from '#~/utils/ts';
|
23
|
+
import { createRequire as createRequire$1, builtinModules } from 'node:module';
|
20
24
|
import { definePlugin, createFilter } from 'jiek/rollup-plugin-utils';
|
21
25
|
import MagicString from 'magic-string';
|
22
|
-
import { builtinModules } from 'node:module';
|
23
26
|
|
24
27
|
const CREATE_REQUIRE_VIRTUAL_MODULE_NAME = "jiek:create-require";
|
25
28
|
const INSERT_STR = (isESM) => `
|
@@ -53,6 +56,8 @@ var progress = (options = {}) => {
|
|
53
56
|
};
|
54
57
|
};
|
55
58
|
|
59
|
+
var require = /* @__PURE__ */ createRequire$1(import.meta.url);
|
60
|
+
|
56
61
|
var replace = definePlugin((options = {}) => {
|
57
62
|
const {
|
58
63
|
include = [/\.[cm]?[tj]sx?$/],
|
@@ -60,39 +65,99 @@ var replace = definePlugin((options = {}) => {
|
|
60
65
|
values = {},
|
61
66
|
sourcemap
|
62
67
|
} = options;
|
68
|
+
let { mode = "string" } = options;
|
63
69
|
const allValues = { ...values };
|
64
70
|
const allKeys = Object.keys(allValues);
|
65
71
|
const filter = createFilter({ include, exclude });
|
66
|
-
const replaceAll = (ctx, code) => {
|
72
|
+
const replaceAll = async (ctx, code) => {
|
67
73
|
const ms = new MagicString(code);
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
match.index + key.length,
|
77
|
-
typeof allValues[key] === "function" ? allValues[key]({
|
74
|
+
if (mode === "string") {
|
75
|
+
allKeys.forEach((key) => {
|
76
|
+
const reg = new RegExp(key, "g");
|
77
|
+
let match;
|
78
|
+
while (match = reg.exec(code)) {
|
79
|
+
const start = match.index;
|
80
|
+
const end = start + key.length;
|
81
|
+
const value = typeof allValues[key] === "function" ? allValues[key]({
|
78
82
|
...ctx,
|
79
83
|
code,
|
80
84
|
start,
|
81
|
-
end
|
82
|
-
|
83
|
-
|
85
|
+
end,
|
86
|
+
mode: "string"
|
87
|
+
}) : allValues[key];
|
88
|
+
if ([null, void 0, false].includes(value)) continue;
|
89
|
+
ms.overwrite(
|
90
|
+
match.index,
|
91
|
+
match.index + key.length,
|
92
|
+
value
|
93
|
+
);
|
94
|
+
}
|
95
|
+
});
|
96
|
+
} else if (mode === "ast-grep") {
|
97
|
+
const ext = extname(ctx.id);
|
98
|
+
const { parse, Lang } = await import('@ast-grep/napi');
|
99
|
+
let lang;
|
100
|
+
if (/[cm]?tsx?/.test(ext)) {
|
101
|
+
lang = Lang.TypeScript;
|
84
102
|
}
|
85
|
-
|
103
|
+
if (/[cm]?jsx?/.test(ext)) {
|
104
|
+
lang = Lang.JavaScript;
|
105
|
+
}
|
106
|
+
if (/json?/.test(ext)) {
|
107
|
+
lang = Lang.Json;
|
108
|
+
}
|
109
|
+
if (lang == null) return;
|
110
|
+
const root = parse(lang, code).root();
|
111
|
+
allKeys.forEach((key) => {
|
112
|
+
root.findAll(key).forEach((node) => {
|
113
|
+
const { start, end } = node.range();
|
114
|
+
let newValue = typeof allValues[key] === "function" ? allValues[key]({
|
115
|
+
...ctx,
|
116
|
+
code,
|
117
|
+
mode: "ast-grep",
|
118
|
+
node,
|
119
|
+
lang,
|
120
|
+
$: (input) => {
|
121
|
+
if (typeof input === "string") {
|
122
|
+
return node.getMatch(input)?.text();
|
123
|
+
}
|
124
|
+
if ("raw" in input) {
|
125
|
+
return node.getMatch(input.raw[0])?.text();
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}) : allValues[key];
|
129
|
+
if ([null, void 0, false].includes(newValue)) return;
|
130
|
+
newValue = newValue.toString();
|
131
|
+
newValue = newValue.replace(/\$([a-z_\-]+)/gi, (_, [name]) => {
|
132
|
+
if (name == null) return _;
|
133
|
+
return node.getMatch(name)?.text() ?? _;
|
134
|
+
});
|
135
|
+
ms.overwrite(start.index, end.index, newValue);
|
136
|
+
});
|
137
|
+
});
|
138
|
+
}
|
86
139
|
return ms;
|
87
140
|
};
|
88
141
|
return {
|
89
142
|
name: "jiek:replace",
|
143
|
+
buildStart() {
|
144
|
+
if (mode === "ast-grep") {
|
145
|
+
try {
|
146
|
+
require.resolve("@ast-grep/napi");
|
147
|
+
this.warn(
|
148
|
+
"You are using `ast-grep` mode, please make sure you have installed `@ast-grep/napi`"
|
149
|
+
);
|
150
|
+
} catch {
|
151
|
+
mode = "string";
|
152
|
+
}
|
153
|
+
}
|
154
|
+
},
|
90
155
|
transform: {
|
91
156
|
order: "pre",
|
92
|
-
handler(code, id) {
|
157
|
+
async handler(code, id) {
|
93
158
|
if (allKeys.length === 0) return;
|
94
159
|
if (filter(id)) return;
|
95
|
-
const ms = replaceAll({ type: "transform", id }, code);
|
160
|
+
const ms = await replaceAll({ type: "transform", id }, code);
|
96
161
|
if (ms == null) return;
|
97
162
|
return {
|
98
163
|
code: ms.toString(),
|
@@ -102,10 +167,10 @@ var replace = definePlugin((options = {}) => {
|
|
102
167
|
},
|
103
168
|
renderChunk: {
|
104
169
|
order: "post",
|
105
|
-
handler(code, { fileName: id }) {
|
170
|
+
async handler(code, { fileName: id }) {
|
106
171
|
if (allKeys.length === 0) return;
|
107
172
|
if (filter(id)) return;
|
108
|
-
const ms = replaceAll({ type: "renderChunk", id }, code);
|
173
|
+
const ms = await replaceAll({ type: "renderChunk", id }, code);
|
109
174
|
if (ms == null) return;
|
110
175
|
return {
|
111
176
|
code: ms.toString(),
|
@@ -257,12 +322,6 @@ const resolveOutputControls = (context, output) => ({
|
|
257
322
|
dts: typeof output?.dts === "boolean" ? output.dts : typeof output?.dts === "function" ? output.dts(context) : true
|
258
323
|
});
|
259
324
|
const resolveWorkspacePath = (p) => resolve(WORKSPACE_ROOT, p);
|
260
|
-
const pascalCase = (str) => str.replace(/[@|/-](\w)/g, (_, $1) => $1.toUpperCase()).replace(/(?:^|-)(\w)/g, (_, $1) => $1.toUpperCase());
|
261
|
-
const reveal = (obj, keys) => keys.reduce((acc, key) => {
|
262
|
-
if (typeof acc === "string") throw new Error("key not found in exports");
|
263
|
-
if (!(key in acc)) throw new Error(`key ${key} not found in exports`);
|
264
|
-
return acc[key];
|
265
|
-
}, obj);
|
266
325
|
const resolveMinifyOptions = (minifyOptions) => typeof minifyOptions === "string" ? { type: minifyOptions } : minifyOptions ?? { type: "esbuild" };
|
267
326
|
const resolveBuilderOptions = (builder) => typeof builder === "string" ? { type: builder } : builder ?? { type: "esbuild" };
|
268
327
|
const resolvedMinifyOptions = resolveMinifyOptions(build.output?.minifyOptions ?? MINIFY_OPTIONS);
|
@@ -416,6 +475,7 @@ const generateConfigs = (context, {
|
|
416
475
|
const rollupOptions = [];
|
417
476
|
const commonPlugins = ({ sourcemap }) => [
|
418
477
|
replace({
|
478
|
+
...build.replacementsOptions,
|
419
479
|
sourcemap: sourcemap === "hidden" ? false : !!sourcemap,
|
420
480
|
values: build.replacements
|
421
481
|
}),
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "jiek",
|
3
3
|
"type": "module",
|
4
|
-
"version": "2.3.
|
4
|
+
"version": "2.3.4",
|
5
5
|
"description": "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.",
|
6
6
|
"author": "YiJie <yijie4188@gmail.com>",
|
7
7
|
"homepage": "https://github.com/NWYLZW/jiek/tree/master/packages/jiek#readme",
|
@@ -56,6 +56,7 @@
|
|
56
56
|
"jb": "bin/build.cjs"
|
57
57
|
},
|
58
58
|
"peerDependencies": {
|
59
|
+
"@ast-grep/napi": "^0.32.3",
|
59
60
|
"@pnpm/filter-workspace-packages": "^7.2.13||^8.0.0||^9.0.0||^10.0.0||>=1000.0.0",
|
60
61
|
"@rollup/plugin-terser": "^0.4.4",
|
61
62
|
"esbuild-register": "^3.5.0",
|
@@ -82,9 +83,12 @@
|
|
82
83
|
"magic-string": "^0.30.17",
|
83
84
|
"rollup": "^4.0.0",
|
84
85
|
"@jiek/pkger": "^0.2.2",
|
85
|
-
"@jiek/utils": "^0.2.
|
86
|
+
"@jiek/utils": "^0.2.4"
|
86
87
|
},
|
87
88
|
"peerDependenciesMeta": {
|
89
|
+
"@ast-grep/napi": {
|
90
|
+
"optional": true
|
91
|
+
},
|
88
92
|
"@pnpm/filter-workspace-packages": {
|
89
93
|
"optional": true
|
90
94
|
},
|
package/src/bin/build.cts
DELETED
package/src/bin/common.ts
DELETED