jiek 0.4.6 → 0.4.7-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. package/README.md +22 -1
  2. package/bin/jiek.js +2 -1
  3. package/dist/cli.d.mts +97 -0
  4. package/dist/cli.d.mts.map +1 -0
  5. package/dist/cli.d.ts +96 -1
  6. package/dist/cli.d.ts.map +1 -0
  7. package/dist/{cli.cjs → cli.js} +355 -231
  8. package/dist/cli.js.map +1 -0
  9. package/dist/cli.min.js +1 -0
  10. package/dist/cli.min.js.map +1 -0
  11. package/dist/cli.min.mjs +1 -0
  12. package/dist/cli.min.mjs.map +1 -0
  13. package/dist/cli.mjs +803 -0
  14. package/dist/cli.mjs.map +1 -0
  15. package/dist/index.d.mts +58 -0
  16. package/dist/index.d.mts.map +1 -0
  17. package/dist/index.d.ts +47 -46
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/{index.cjs → index.js} +0 -1
  20. package/dist/index.js.map +1 -0
  21. package/dist/{index.min.cjs → index.min.js} +0 -1
  22. package/dist/index.min.js.map +1 -0
  23. package/dist/index.min.mjs +1 -0
  24. package/dist/index.min.mjs.map +1 -0
  25. package/dist/{index.esm.js → index.mjs} +0 -1
  26. package/dist/index.mjs.map +1 -0
  27. package/dist/rollup/index.d.mts +53 -0
  28. package/dist/rollup/index.d.mts.map +1 -0
  29. package/dist/rollup/index.d.ts +53 -0
  30. package/dist/rollup/index.d.ts.map +1 -0
  31. package/dist/rollup/index.js +553 -0
  32. package/dist/rollup/index.js.map +1 -0
  33. package/dist/rollup/index.min.js +1 -0
  34. package/dist/rollup/index.min.js.map +1 -0
  35. package/dist/rollup/index.min.mjs +1 -0
  36. package/dist/rollup/index.min.mjs.map +1 -0
  37. package/dist/rollup/index.mjs +551 -0
  38. package/dist/rollup/index.mjs.map +1 -0
  39. package/package.json +52 -35
  40. package/src/cli.ts +9 -0
  41. package/src/commands/base.ts +9 -0
  42. package/src/commands/build.ts +156 -0
  43. package/src/commands/init.ts +373 -0
  44. package/src/commands/publish.ts +156 -0
  45. package/src/index.ts +8 -0
  46. package/src/inner.ts +11 -0
  47. package/src/merge-package-json.ts +75 -0
  48. package/src/pkg.ts +1 -0
  49. package/src/rollup/base.ts +72 -0
  50. package/src/rollup/index.ts +420 -0
  51. package/src/rollup/plugins/globals.ts +34 -0
  52. package/src/rollup/plugins/progress.ts +26 -0
  53. package/src/rollup/plugins/skip.ts +23 -0
  54. package/src/rollup/utils/commonOptions.ts +9 -0
  55. package/src/rollup/utils/externalResolver.ts +21 -0
  56. package/src/rollup/utils/globalResolver.ts +13 -0
  57. package/src/rollup/utils/withMinify.ts +18 -0
  58. package/src/utils/filterSupport.ts +82 -0
  59. package/src/utils/getExports.ts +100 -0
  60. package/src/utils/getRoot.ts +16 -0
  61. package/src/utils/getWD.ts +31 -0
  62. package/src/utils/loadConfig.ts +93 -0
  63. package/src/utils/tsRegister.ts +22 -0
  64. package/dist/base.esm.d.ts +0 -55
  65. package/dist/cli.cjs.map +0 -1
  66. package/dist/cli.esm.d.ts +0 -2
  67. package/dist/cli.esm.js +0 -9
  68. package/dist/cli.esm.js.map +0 -1
  69. package/dist/cli.esm.min.js +0 -2
  70. package/dist/cli.esm.min.js.map +0 -1
  71. package/dist/cli.min.cjs +0 -2
  72. package/dist/cli.min.cjs.map +0 -1
  73. package/dist/commands/base.esm.js +0 -5
  74. package/dist/commands/base.esm.js.map +0 -1
  75. package/dist/commands/base.esm.min.js +0 -2
  76. package/dist/commands/base.esm.min.js.map +0 -1
  77. package/dist/commands/build.esm.js +0 -58
  78. package/dist/commands/build.esm.js.map +0 -1
  79. package/dist/commands/build.esm.min.js +0 -2
  80. package/dist/commands/build.esm.min.js.map +0 -1
  81. package/dist/commands/init.esm.js +0 -271
  82. package/dist/commands/init.esm.js.map +0 -1
  83. package/dist/commands/init.esm.min.js +0 -2
  84. package/dist/commands/init.esm.min.js.map +0 -1
  85. package/dist/commands/publish.esm.js +0 -87
  86. package/dist/commands/publish.esm.js.map +0 -1
  87. package/dist/commands/publish.esm.min.js +0 -2
  88. package/dist/commands/publish.esm.min.js.map +0 -1
  89. package/dist/index.cjs.map +0 -1
  90. package/dist/index.esm.d.ts +0 -6
  91. package/dist/index.esm.js.map +0 -1
  92. package/dist/index.esm.min.js +0 -2
  93. package/dist/index.esm.min.js.map +0 -1
  94. package/dist/index.min.cjs.map +0 -1
  95. package/dist/inner.esm.js +0 -10
  96. package/dist/inner.esm.js.map +0 -1
  97. package/dist/inner.esm.min.js +0 -2
  98. package/dist/inner.esm.min.js.map +0 -1
  99. package/dist/merge-package-json.esm.js +0 -64
  100. package/dist/merge-package-json.esm.js.map +0 -1
  101. package/dist/merge-package-json.esm.min.js +0 -2
  102. package/dist/merge-package-json.esm.min.js.map +0 -1
  103. package/dist/pkg.esm.js +0 -4
  104. package/dist/pkg.esm.js.map +0 -1
  105. package/dist/pkg.esm.min.js +0 -2
  106. package/dist/pkg.esm.min.js.map +0 -1
  107. package/dist/rollup/plugins/globals.esm.js +0 -31
  108. package/dist/rollup/plugins/globals.esm.js.map +0 -1
  109. package/dist/rollup/plugins/globals.esm.min.js +0 -2
  110. package/dist/rollup/plugins/globals.esm.min.js.map +0 -1
  111. package/dist/rollup/plugins/skip.esm.js +0 -16
  112. package/dist/rollup/plugins/skip.esm.js.map +0 -1
  113. package/dist/rollup/plugins/skip.esm.min.js +0 -2
  114. package/dist/rollup/plugins/skip.esm.min.js.map +0 -1
  115. package/dist/rollup/utils/commonOptions.esm.js +0 -9
  116. package/dist/rollup/utils/commonOptions.esm.js.map +0 -1
  117. package/dist/rollup/utils/commonOptions.esm.min.js +0 -2
  118. package/dist/rollup/utils/commonOptions.esm.min.js.map +0 -1
  119. package/dist/rollup/utils/externalResolver.esm.js +0 -12
  120. package/dist/rollup/utils/externalResolver.esm.js.map +0 -1
  121. package/dist/rollup/utils/externalResolver.esm.min.js +0 -2
  122. package/dist/rollup/utils/externalResolver.esm.min.js.map +0 -1
  123. package/dist/rollup/utils/globalResolver.esm.js +0 -9
  124. package/dist/rollup/utils/globalResolver.esm.js.map +0 -1
  125. package/dist/rollup/utils/globalResolver.esm.min.js +0 -2
  126. package/dist/rollup/utils/globalResolver.esm.min.js.map +0 -1
  127. package/dist/rollup/utils/withMinify.esm.js +0 -15
  128. package/dist/rollup/utils/withMinify.esm.js.map +0 -1
  129. package/dist/rollup/utils/withMinify.esm.min.js +0 -2
  130. package/dist/rollup/utils/withMinify.esm.min.js.map +0 -1
  131. package/dist/rollup.cjs +0 -330
  132. package/dist/rollup.cjs.map +0 -1
  133. package/dist/rollup.d.ts +0 -23
  134. package/dist/rollup.esm.d.ts +0 -23
  135. package/dist/rollup.esm.js +0 -248
  136. package/dist/rollup.esm.js.map +0 -1
  137. package/dist/rollup.esm.min.js +0 -2
  138. package/dist/rollup.esm.min.js.map +0 -1
  139. package/dist/rollup.min.cjs +0 -2
  140. package/dist/rollup.min.cjs.map +0 -1
  141. package/dist/utils/commondir.esm.js +0 -25
  142. package/dist/utils/commondir.esm.js.map +0 -1
  143. package/dist/utils/commondir.esm.min.js +0 -2
  144. package/dist/utils/commondir.esm.min.js.map +0 -1
  145. package/dist/utils/filterSupport.esm.js +0 -67
  146. package/dist/utils/filterSupport.esm.js.map +0 -1
  147. package/dist/utils/filterSupport.esm.min.js +0 -2
  148. package/dist/utils/filterSupport.esm.min.js.map +0 -1
  149. package/dist/utils/getRoot.esm.js +0 -14
  150. package/dist/utils/getRoot.esm.js.map +0 -1
  151. package/dist/utils/getRoot.esm.min.js +0 -2
  152. package/dist/utils/getRoot.esm.min.js.map +0 -1
  153. package/dist/utils/getWD.esm.js +0 -31
  154. package/dist/utils/getWD.esm.js.map +0 -1
  155. package/dist/utils/getWD.esm.min.js +0 -2
  156. package/dist/utils/getWD.esm.min.js.map +0 -1
  157. package/dist/utils/loadConfig.esm.js +0 -75
  158. package/dist/utils/loadConfig.esm.js.map +0 -1
  159. package/dist/utils/loadConfig.esm.min.js +0 -2
  160. package/dist/utils/loadConfig.esm.min.js.map +0 -1
  161. package/dist/utils/tsRegister.esm.js +0 -24
  162. package/dist/utils/tsRegister.esm.js.map +0 -1
  163. package/dist/utils/tsRegister.esm.min.js +0 -2
  164. package/dist/utils/tsRegister.esm.min.js.map +0 -1
@@ -0,0 +1,553 @@
1
+ 'use strict';
2
+
3
+ var fs = require('node:fs');
4
+ var path = require('node:path');
5
+ var entrypoints = require('@jiek/pkger/entrypoints');
6
+ var rollupPluginDts = require('@jiek/rollup-plugin-dts');
7
+ var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
8
+ var json = require('@rollup/plugin-json');
9
+ var pluginNodeResolve = require('@rollup/plugin-node-resolve');
10
+ var terser = require('@rollup/plugin-terser');
11
+ var execa = require('execa');
12
+ var jsoncParser = require('jsonc-parser');
13
+ var micromatch = require('micromatch');
14
+ var esbuild = require('rollup-plugin-esbuild');
15
+ var ts = require('typescript');
16
+ var commander = require('commander');
17
+ var jsYaml = require('js-yaml');
18
+ require('@pnpm/filter-workspace-packages');
19
+
20
+ const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
21
+ function getExports({
22
+ entrypoints: entrypoints$1,
23
+ pkgIsModule,
24
+ entries,
25
+ config,
26
+ dir,
27
+ noFilter
28
+ }) {
29
+ const dirResolve = (...paths) => path.resolve(dir ?? process.cwd(), ...paths);
30
+ const dirRelative = (path$1) => path.relative(dir ?? process.cwd(), path$1);
31
+ const { build = {} } = config ?? {};
32
+ const {
33
+ crossModuleConvertor = true
34
+ } = build;
35
+ const jsOutdir = `./${dirRelative(dirResolve(
36
+ (typeof build?.output?.dir === "object" ? build.output.dir.js : build?.output?.dir) ?? "dist"
37
+ ))}`;
38
+ const [, resolvedEntrypoints] = entrypoints.resolveEntrypoints(entrypoints$1);
39
+ if (entries) {
40
+ Object.entries(resolvedEntrypoints).forEach(([key]) => {
41
+ if (!entries.some((e) => micromatch.isMatch(key, e, { matchBase: true }))) {
42
+ delete resolvedEntrypoints[key];
43
+ }
44
+ });
45
+ }
46
+ const filteredResolvedEntrypoints = noFilter ? resolvedEntrypoints : entrypoints.filterLeafs(
47
+ resolvedEntrypoints,
48
+ {
49
+ skipValue: [
50
+ // ignore values that filename starts with `.jk-noentry`
51
+ /(^|\/)\.jk-noentry/,
52
+ ...entrypoints.DEFAULT_SKIP_VALUES
53
+ ]
54
+ }
55
+ );
56
+ const crossModuleWithConditional = crossModuleConvertor ? {
57
+ import: (opts) => !pkgIsModule && intersection(
58
+ new Set(opts.conditionals),
59
+ /* @__PURE__ */ new Set(["import", "module"])
60
+ ).size === 0 ? opts.dist.replace(/\.js$/, ".mjs") : false,
61
+ require: (opts) => pkgIsModule && intersection(
62
+ new Set(opts.conditionals),
63
+ /* @__PURE__ */ new Set(["require", "node"])
64
+ ).size === 0 ? opts.dist.replace(/\.js$/, ".cjs") : false
65
+ } : {};
66
+ return [
67
+ filteredResolvedEntrypoints,
68
+ entrypoints.entrypoints2Exports(filteredResolvedEntrypoints, {
69
+ outdir: jsOutdir,
70
+ withConditional: {
71
+ ...crossModuleWithConditional
72
+ }
73
+ })
74
+ ];
75
+ }
76
+
77
+ let root;
78
+ function getRoot() {
79
+ if (root)
80
+ return root;
81
+ const rootOption = commander.program.getOptionValue("root");
82
+ root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : void 0;
83
+ return root;
84
+ }
85
+
86
+ let type = "";
87
+ try {
88
+ require.resolve("@pnpm/filter-workspace-packages");
89
+ type = "pnpm";
90
+ } catch {
91
+ }
92
+ if (type !== "") {
93
+ commander.program.option("-f, --filter <filter>", "filter packages");
94
+ }
95
+
96
+ let wd;
97
+ let notWorkspace = false;
98
+ function getWD() {
99
+ if (wd)
100
+ return { wd, notWorkspace };
101
+ const root = getRoot();
102
+ if (root !== void 0) {
103
+ const isWorkspace = getWorkspaceDir.isWorkspaceDir(root, type);
104
+ notWorkspace = !isWorkspace;
105
+ wd = root;
106
+ return { wd, notWorkspace };
107
+ }
108
+ try {
109
+ wd = getWorkspaceDir.getWorkspaceDir(type);
110
+ } catch (e) {
111
+ if ("message" in e && e.message === "workspace root not found") {
112
+ wd = root;
113
+ notWorkspace = true;
114
+ } else {
115
+ throw e;
116
+ }
117
+ }
118
+ return { wd, notWorkspace };
119
+ }
120
+
121
+ function packageIsExist(name) {
122
+ try {
123
+ require.resolve(name);
124
+ return true;
125
+ } catch (e) {
126
+ return false;
127
+ }
128
+ }
129
+ let tsRegisterName;
130
+ const registers = [
131
+ process.env.JIEK_TS_REGISTER,
132
+ "esbuild-register",
133
+ "@swc-node/register",
134
+ "ts-node/register"
135
+ ].filter(Boolean);
136
+ for (const register of registers) {
137
+ if (packageIsExist(register)) {
138
+ tsRegisterName = register;
139
+ break;
140
+ }
141
+ }
142
+
143
+ let configName = "jiek.config";
144
+ function getConfigPath(root, dir) {
145
+ const isSupportTsLoader = !!tsRegisterName;
146
+ function configWithExtIsExist(ext) {
147
+ const filenames = [
148
+ path.resolve(process.cwd(), `${configName}.${ext}`),
149
+ path.resolve(process.cwd(), `.${configName}.${ext}`),
150
+ path.resolve(root, `${configName}.${ext}`),
151
+ path.resolve(root, `.${configName}.${ext}`)
152
+ ];
153
+ if (dir) {
154
+ filenames.unshift(...[
155
+ path.resolve(dir, `${configName}.${ext}`),
156
+ path.resolve(dir, `.${configName}.${ext}`)
157
+ ]);
158
+ }
159
+ for (const filename of filenames) {
160
+ if (fs.existsSync(filename) && fs.lstatSync(filename).isFile()) {
161
+ return filename;
162
+ }
163
+ }
164
+ return;
165
+ }
166
+ configName = configWithExtIsExist("js") ?? configName;
167
+ configName = configWithExtIsExist("json") ?? configName;
168
+ configName = configWithExtIsExist("yaml") ?? configName;
169
+ if (isSupportTsLoader) {
170
+ configName = configWithExtIsExist("ts") ?? configName;
171
+ }
172
+ return path.resolve(root, configName);
173
+ }
174
+ function loadConfig(dir) {
175
+ const { wd: root } = getWD();
176
+ let configPath = commander.program.getOptionValue("configPath");
177
+ if (!configPath) {
178
+ configPath = getConfigPath(root, dir);
179
+ } else {
180
+ if (!fs.existsSync(configPath)) {
181
+ throw new Error(`config file not found: ${configPath}`);
182
+ }
183
+ if (!path.isAbsolute(configPath)) {
184
+ configPath = path.resolve(root, configPath);
185
+ }
186
+ }
187
+ const ext = path.extname(configPath);
188
+ let module;
189
+ switch (ext) {
190
+ case ".js":
191
+ module = require(configPath);
192
+ break;
193
+ case ".json":
194
+ return require(configPath);
195
+ case ".yaml":
196
+ return jsYaml.load(fs.readFileSync(configPath, "utf-8"));
197
+ case ".ts":
198
+ if (tsRegisterName) {
199
+ require(tsRegisterName);
200
+ module = require(configPath);
201
+ break;
202
+ }
203
+ throw new Error(
204
+ "ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register"
205
+ );
206
+ case ".config":
207
+ module = {};
208
+ break;
209
+ default:
210
+ throw new Error(`unsupported config file type: ${ext}`);
211
+ }
212
+ if (!module)
213
+ throw new Error("config file is empty");
214
+ return module.default ?? module;
215
+ }
216
+
217
+ var progress = (options = {}) => {
218
+ const { onEvent } = options;
219
+ return {
220
+ name: "progress",
221
+ buildStart: () => onEvent?.("start", "Start building..."),
222
+ buildEnd: () => onEvent?.("end", "Build completed!"),
223
+ resolveId: {
224
+ order: "post",
225
+ handler: (source) => onEvent?.("resolve", `Resolving ${source}...`)
226
+ },
227
+ load: {
228
+ order: "post",
229
+ handler: (id) => onEvent?.("load", `Loading ${id}...`)
230
+ },
231
+ transform: {
232
+ order: "post",
233
+ handler: (_, id) => onEvent?.("transform", `Transforming ${id}...`)
234
+ }
235
+ };
236
+ };
237
+
238
+ var skip = (options = {}) => {
239
+ return {
240
+ name: "skip",
241
+ // skip the specified files by `options.patterns`
242
+ load(id) {
243
+ if (options.patterns?.some(
244
+ (pattern) => typeof pattern === "string" ? id.includes(pattern) : pattern.test(id)
245
+ )) {
246
+ return "";
247
+ }
248
+ }
249
+ };
250
+ };
251
+
252
+ function externalResolver(jsonOrPath = process.cwd()) {
253
+ const pkg = typeof jsonOrPath === "string" ? fs.existsSync(`${jsonOrPath}/package.json`) ? JSON.parse(fs.readFileSync(`${jsonOrPath}/package.json`, "utf-8")) : {} : jsonOrPath;
254
+ const { dependencies = {}, peerDependencies = {}, optionalDependencies = {} } = pkg;
255
+ const external = Object.keys(dependencies).concat(Object.keys(peerDependencies)).concat(Object.keys(optionalDependencies));
256
+ return external.map((dep) => new RegExp(`^${dep}(/.*)?$`)).concat([
257
+ /^node:/
258
+ ]);
259
+ }
260
+
261
+ const {
262
+ JIEK_ROOT,
263
+ JIEK_ENTRIES
264
+ } = process.env;
265
+ const WORKSPACE_ROOT = JIEK_ROOT ?? getWorkspaceDir.getWorkspaceDir();
266
+ const COMMON_OPTIONS = {};
267
+ const COMMON_PLUGINS = [
268
+ json()
269
+ ];
270
+ const config = loadConfig() ?? {};
271
+ const { build = {} } = config;
272
+ const jsOutdir = `./${path.relative(
273
+ process.cwd(),
274
+ path.resolve(
275
+ (typeof build?.output?.dir === "object" ? build.output.dir.js : build?.output?.dir) ?? "dist"
276
+ )
277
+ )}`;
278
+ const STYLE_REGEXP = /\.(css|s[ac]ss|less|styl)$/;
279
+ const resolveWorkspacePath = (p) => path.resolve(WORKSPACE_ROOT, p);
280
+ const pascalCase = (str) => str.replace(/[@|/-](\w)/g, (_, $1) => $1.toUpperCase()).replace(/(?:^|-)(\w)/g, (_, $1) => $1.toUpperCase());
281
+ const reveal = (obj, keys) => keys.reduce((acc, key) => {
282
+ if (typeof acc === "string")
283
+ throw new Error("key not found in exports");
284
+ if (!(key in acc))
285
+ throw new Error(`key ${key} not found in exports`);
286
+ return acc[key];
287
+ }, obj);
288
+ const withMinify = (output, minify = build?.output?.minify) => minify === false ? [output] : minify === "only-minify" ? [{
289
+ ...output,
290
+ // TODO replace suffix when pubish to npm and the `build.output.minify` is 'only-minify'
291
+ // TODO resolve dts output file name
292
+ file: output.file?.replace(/(\.[cm]?js)$/, ".min$1"),
293
+ plugins: [
294
+ ...output.plugins ?? [],
295
+ terser()
296
+ ]
297
+ }] : [
298
+ output,
299
+ {
300
+ ...output,
301
+ file: output.file?.replace(/(\.[cm]?js)$/, ".min$1"),
302
+ plugins: [
303
+ ...output.plugins ?? [],
304
+ terser()
305
+ ]
306
+ }
307
+ ];
308
+ const getTSConfig = (p) => !fs.existsSync(p) || !fs.statSync(p).isFile() ? {} : jsoncParser.parse(fs.readFileSync(p, "utf-8"), [], { allowTrailingComma: true, allowEmptyContent: true });
309
+ const getExtendTSConfig = (tsconfigPath) => {
310
+ tsconfigPath = path.resolve(tsconfigPath);
311
+ const tsconfigPathDirname = path.dirname(tsconfigPath);
312
+ const { extends: exts, ...tsconfig } = getTSConfig(tsconfigPath);
313
+ const resolvePaths = (paths) => paths?.map((p) => path.resolve(tsconfigPathDirname, p)) ?? [];
314
+ const extendsPaths = resolvePaths(
315
+ exts ? Array.isArray(exts) ? exts : [exts] : []
316
+ );
317
+ if (extendsPaths.length === 0)
318
+ return tsconfig;
319
+ return extendsPaths.map(getExtendTSConfig).reduce((acc, { compilerOptions = {}, references: _, ...curr }) => ({
320
+ ...acc,
321
+ ...curr,
322
+ compilerOptions: {
323
+ ...acc.compilerOptions,
324
+ ...compilerOptions
325
+ }
326
+ }), tsconfig);
327
+ };
328
+ const getCompilerOptionsByFilePath = (tsconfigPath, filePath) => {
329
+ tsconfigPath = path.resolve(tsconfigPath);
330
+ filePath = path.resolve(filePath);
331
+ const tsconfigPathDirname = path.dirname(tsconfigPath);
332
+ const tsconfig = getExtendTSConfig(tsconfigPath);
333
+ const resolvePaths = (paths) => paths?.map((p) => path.resolve(tsconfigPathDirname, p)) ?? [];
334
+ const [
335
+ references,
336
+ files,
337
+ include,
338
+ exclude
339
+ ] = [
340
+ tsconfig.references?.map(({ path }) => path),
341
+ tsconfig.files,
342
+ tsconfig.include,
343
+ tsconfig.exclude
344
+ ].map(resolvePaths);
345
+ if (exclude.length > 0 && exclude.some((i) => micromatch.isMatch(filePath, i)))
346
+ return;
347
+ if (tsconfig.files?.length === 0 && tsconfig.include?.length === 0)
348
+ return;
349
+ let isInclude = false;
350
+ isInclude || (isInclude = files.length > 0 && files.includes(filePath));
351
+ isInclude || (isInclude = include.length > 0 && include.some((i) => micromatch.isMatch(filePath, i)));
352
+ if (isInclude) {
353
+ return tsconfig.compilerOptions ?? {};
354
+ } else {
355
+ if (tsconfig.files && tsconfig.files.length > 0 || tsconfig.include && tsconfig.include.length > 0)
356
+ return;
357
+ }
358
+ references.reverse();
359
+ for (const ref of references) {
360
+ const compilerOptions = getCompilerOptionsByFilePath(ref, filePath);
361
+ if (compilerOptions)
362
+ return compilerOptions;
363
+ }
364
+ return tsconfig.compilerOptions;
365
+ };
366
+ const generateConfigs = ({
367
+ path: path$1,
368
+ name,
369
+ input,
370
+ output,
371
+ external,
372
+ pkgIsModule,
373
+ conditionals
374
+ }, options = {}) => {
375
+ const isModule = conditionals.includes("import");
376
+ const isCommonJS = conditionals.includes("require");
377
+ const isBrowser = conditionals.includes("browser");
378
+ const dtsTSConfigPaths = [
379
+ resolveWorkspacePath("tsconfig.json"),
380
+ resolveWorkspacePath("tsconfig.dts.json")
381
+ ];
382
+ let dtsTSConfigPath;
383
+ dtsTSConfigPaths.forEach((p) => {
384
+ if (fs.existsSync(p) && fs.statSync(p).isFile()) {
385
+ dtsTSConfigPath = p;
386
+ }
387
+ });
388
+ let compilerOptions = {};
389
+ if (dtsTSConfigPath) {
390
+ const jsonCompilerOptions = getCompilerOptionsByFilePath(dtsTSConfigPath, path.resolve(input));
391
+ const { options: options2, errors } = ts.convertCompilerOptionsFromJson(
392
+ jsonCompilerOptions,
393
+ path.dirname(dtsTSConfigPath)
394
+ );
395
+ if (errors.length > 0) {
396
+ throw new Error(errors.map((e) => e.messageText).join("\n"));
397
+ }
398
+ compilerOptions = options2;
399
+ }
400
+ const exportConditions = [...conditionals, ...compilerOptions.customConditions ?? []];
401
+ const throughEventProps = {
402
+ type: "progress",
403
+ data: { name, path: path$1, exportConditions, input }
404
+ };
405
+ const outdir = options?.output?.dir;
406
+ return [
407
+ {
408
+ input,
409
+ external,
410
+ output: [
411
+ ...withMinify({
412
+ file: output,
413
+ name,
414
+ sourcemap: typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.js : options?.output?.sourcemap,
415
+ format: isModule ? "esm" : isCommonJS ? "cjs" : isBrowser ? "umd" : pkgIsModule ? "esm" : "cjs",
416
+ strict: typeof options?.output?.strict === "object" ? options.output.strict.js : options?.output?.strict
417
+ })
418
+ ],
419
+ plugins: [
420
+ pluginNodeResolve.nodeResolve({ exportConditions }),
421
+ import('rollup-plugin-postcss').then(
422
+ ({ default: postcss }) => postcss({
423
+ extract: path.resolve(output.replace(/\.[cm]?js$/, ".css")),
424
+ minimize: true
425
+ })
426
+ ).catch(() => void 0),
427
+ esbuild(),
428
+ progress({
429
+ onEvent: (event, message) => execa.sendMessage(
430
+ {
431
+ ...throughEventProps,
432
+ data: { ...throughEventProps.data, event, message, tags: ["js"] }
433
+ }
434
+ )
435
+ })
436
+ ]
437
+ },
438
+ {
439
+ input,
440
+ external,
441
+ output: [
442
+ {
443
+ dir: path.resolve((typeof outdir === "object" ? outdir.dts : outdir) ?? "dist"),
444
+ sourcemap: typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.dts : options?.output?.sourcemap,
445
+ entryFileNames: () => output.replace(`${jsOutdir}/`, "").replace(/(\.[cm]?)js$/, ".d$1ts"),
446
+ strict: typeof options?.output?.strict === "object" ? options.output.strict.dts : options?.output?.strict
447
+ }
448
+ ],
449
+ plugins: [
450
+ pluginNodeResolve.nodeResolve({ exportConditions }),
451
+ skip({ patterns: [STYLE_REGEXP] }),
452
+ rollupPluginDts.dts({
453
+ respectExternal: true,
454
+ compilerOptions
455
+ }),
456
+ progress({
457
+ onEvent: (event, message) => execa.sendMessage(
458
+ {
459
+ ...throughEventProps,
460
+ data: { ...throughEventProps.data, event, message, tags: ["dts"] }
461
+ }
462
+ )
463
+ })
464
+ ]
465
+ }
466
+ ];
467
+ };
468
+ function template(packageJSON) {
469
+ const { name, type, exports: entrypoints$1 } = packageJSON;
470
+ const pkgIsModule = type === "module";
471
+ if (!name)
472
+ throw new Error("package.json name is required");
473
+ if (!entrypoints$1)
474
+ throw new Error("package.json exports is required");
475
+ const entries = JIEK_ENTRIES?.split(",").map((e) => e.trim()).map((e) => ({
476
+ "index": "."
477
+ })[e] ?? e);
478
+ const packageName = pascalCase(name);
479
+ const external = externalResolver(packageJSON);
480
+ const [filteredResolvedEntrypoints, exports] = getExports({
481
+ entrypoints: entrypoints$1,
482
+ pkgIsModule,
483
+ entries,
484
+ config
485
+ });
486
+ const leafMap = /* @__PURE__ */ new Map();
487
+ entrypoints.getAllLeafs(filteredResolvedEntrypoints, ({ keys, value }) => {
488
+ if (typeof value === "string") {
489
+ const keysArr = leafMap.get(value) ?? [];
490
+ leafMap.set(value, keysArr);
491
+ keysArr.push(keys);
492
+ }
493
+ return false;
494
+ });
495
+ const configs = [];
496
+ leafMap.forEach(
497
+ (keysArr, input) => keysArr.forEach((keys) => {
498
+ const [path, ...conditionals] = keys;
499
+ const name2 = packageName + (path === "." ? "" : pascalCase(path));
500
+ const keyExports = reveal(exports, keys);
501
+ const commonOptions = {
502
+ path,
503
+ name: name2,
504
+ input,
505
+ external,
506
+ pkgIsModule
507
+ };
508
+ switch (typeof keyExports) {
509
+ case "string": {
510
+ configs.push(...generateConfigs({
511
+ ...commonOptions,
512
+ output: keyExports,
513
+ conditionals
514
+ }, build));
515
+ break;
516
+ }
517
+ case "object": {
518
+ entrypoints.getAllLeafs(keyExports, ({ keys: nextKeys, value }) => {
519
+ const allConditionals = [.../* @__PURE__ */ new Set([...conditionals, ...nextKeys])];
520
+ if (typeof value === "string") {
521
+ configs.push(...generateConfigs({
522
+ ...commonOptions,
523
+ output: value,
524
+ conditionals: allConditionals
525
+ }, build));
526
+ }
527
+ return false;
528
+ });
529
+ break;
530
+ }
531
+ }
532
+ })
533
+ );
534
+ execa.sendMessage(
535
+ {
536
+ type: "init",
537
+ data: {
538
+ leafMap,
539
+ targetsLength: configs.length
540
+ }
541
+ }
542
+ );
543
+ return configs.map((c) => ({
544
+ ...COMMON_OPTIONS,
545
+ ...c,
546
+ plugins: [
547
+ ...COMMON_PLUGINS,
548
+ c.plugins
549
+ ]
550
+ }));
551
+ }
552
+
553
+ exports.template = template;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/utils/getRoot.ts","../../src/utils/filterSupport.ts","../../src/utils/getWD.ts","../../src/utils/tsRegister.ts","../../src/utils/loadConfig.ts","../../src/rollup/plugins/progress.ts","../../src/rollup/plugins/skip.ts","../../src/rollup/utils/externalResolver.ts","../../src/rollup/index.ts"],"sourcesContent":["import path from 'node:path'\n\nimport { program } from 'commander'\n\nlet root: string\nexport function getRoot() {\n if (root) return root\n\n const rootOption = program.getOptionValue('root')\n root = rootOption\n ? path.isAbsolute(rootOption)\n ? rootOption\n : path.resolve(process.cwd(), rootOption)\n : undefined\n return root\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { filterPackagesFromDir } from '@pnpm/filter-workspace-packages'\nimport { program } from 'commander'\nimport { load } from 'js-yaml'\n\nimport { getRoot } from './getRoot'\nimport { getWD } from './getWD'\n\nexport let type = ''\n\ntry {\n require.resolve('@pnpm/filter-workspace-packages')\n type = 'pnpm'\n} catch { /* empty */ }\nif (type !== '') {\n program\n .option('-f, --filter <filter>', 'filter packages')\n}\n\ninterface ProjectsGraph {\n wd: string\n root: string\n value?: Record<string, {\n name?: string\n }>\n}\n\nexport async function getSelectedProjectsGraph(): Promise<ProjectsGraph> {\n let filter = program.getOptionValue('filter')\n const root = getRoot()\n const { wd, notWorkspace } = getWD()\n if (!notWorkspace && type === 'pnpm') {\n const pnpmWorkspaceFilePath = path.resolve(wd, 'pnpm-workspace.yaml')\n const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, 'utf-8')\n const pnpmWorkspace = load(pnpmWorkspaceFileContent) as {\n packages: string[]\n }\n if (root === wd && !filter) {\n throw new Error('root path is workspace root, please provide a filter')\n // TODO inquirer prompt support user select packages\n }\n if (root !== wd && !filter) {\n const packageJSONIsExist = fs.existsSync(path.resolve(root, 'package.json'))\n if (!packageJSONIsExist) {\n throw new Error('root path is not workspace root, please provide a filter')\n }\n const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, 'package.json'), 'utf-8'))\n if (!packageJSON.name) {\n throw new Error('root path is not workspace root, please provide a filter')\n }\n filter = packageJSON.name\n }\n const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{\n filter: filter ?? '',\n followProdDepsOnly: true\n }], {\n prefix: root,\n workspaceDir: wd,\n patterns: pnpmWorkspace.packages\n })\n return {\n wd,\n root,\n value: Object.entries(selectedProjectsGraph)\n .reduce((acc, [key, value]) => {\n acc[key] = value.package.manifest\n return acc\n }, {} as NonNullable<ProjectsGraph['value']>)\n }\n }\n return {\n wd,\n root,\n value: {\n [wd]: JSON.parse(fs.readFileSync(path.resolve(wd, 'package.json'), 'utf-8'))\n }\n }\n}\n","import { getWorkspaceDir, isWorkspaceDir } from '@jiek/utils/getWorkspaceDir'\n\nimport { type } from './filterSupport'\nimport { getRoot } from './getRoot'\n\nlet wd: string\nlet notWorkspace = false\n\nexport function getWD() {\n if (wd) return { wd, notWorkspace }\n\n const root = getRoot()\n if (root !== undefined) {\n const isWorkspace = isWorkspaceDir(root, type)\n notWorkspace = !isWorkspace\n wd = root\n return { wd, notWorkspace }\n }\n try {\n wd = getWorkspaceDir(type)\n } catch (e) {\n // @ts-ignore\n if ('message' in e && e.message === 'workspace root not found') {\n wd = root\n notWorkspace = true\n } else {\n throw e\n }\n }\n return { wd, notWorkspace }\n}\n","function packageIsExist(name: string) {\n try {\n require.resolve(name)\n return true\n } catch (e) {\n return false\n }\n}\n\nexport let tsRegisterName: string | undefined\nconst registers = [\n process.env.JIEK_TS_REGISTER,\n 'esbuild-register',\n '@swc-node/register',\n 'ts-node/register'\n].filter(Boolean) as string[]\nfor (const register of registers) {\n if (packageIsExist(register)) {\n tsRegisterName = register\n break\n }\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { program } from 'commander'\nimport type { Config } from 'jiek'\nimport { load } from 'js-yaml'\n\nimport { getWD } from './getWD'\nimport { tsRegisterName } from './tsRegister'\n\nlet configName = 'jiek.config'\n\nfunction getConfigPath(root: string) {\n const isSupportTsLoader = !!tsRegisterName\n function configWithExtIsExist(ext: string) {\n const filenames = [\n path.resolve(process.cwd(), `${configName}.${ext}`),\n path.resolve(process.cwd(), `.${configName}.${ext}`),\n path.resolve(root, `${configName}.${ext}`),\n path.resolve(root, `.${configName}.${ext}`)\n ]\n for (const filename of filenames) {\n if (\n fs.existsSync(filename)\n && fs.lstatSync(filename)\n .isFile()\n ) {\n return filename\n }\n }\n return\n }\n configName = configWithExtIsExist('js') ?? configName\n configName = configWithExtIsExist('json') ?? configName\n configName = configWithExtIsExist('yaml') ?? configName\n if (isSupportTsLoader) {\n configName = configWithExtIsExist('ts') ?? configName\n }\n return path.resolve(root, configName)\n}\n\nexport function loadConfig(): Config {\n const { wd: root, notWorkspace } = getWD()\n if (notWorkspace) {\n throw new Error('not in workspace')\n }\n\n let configPath = program.getOptionValue('configPath')\n\n if (!configPath) {\n configPath = getConfigPath(root)\n } else {\n if (!fs.existsSync(configPath)) {\n throw new Error(`config file not found: ${configPath}`)\n }\n if (!path.isAbsolute(configPath)) {\n configPath = path.resolve(root, configPath)\n }\n }\n const ext = path.extname(configPath)\n\n let module: any\n switch (ext) {\n case '.js':\n module = require(configPath)\n break\n case '.json':\n return require(configPath)\n case '.yaml':\n return load(fs.readFileSync(configPath, 'utf-8')) as Config\n case '.ts':\n if (tsRegisterName) {\n require(tsRegisterName)\n module = require(configPath)\n break\n }\n throw new Error(\n 'ts config file is not supported without ts register, '\n + 'please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register'\n )\n case '.config':\n module = {}\n break\n default:\n throw new Error(`unsupported config file type: ${ext}`)\n }\n if (!module) throw new Error('config file is empty')\n\n return module.default ?? module\n}\n","import type { PluginImpl } from 'rollup'\n\ninterface Options {\n onEvent?: (event: string, message?: string) => void\n}\n\nexport default ((options = {}) => {\n const { onEvent } = options\n return {\n name: 'progress',\n buildStart: () => onEvent?.('start', 'Start building...'),\n buildEnd: () => onEvent?.('end', 'Build completed!'),\n resolveId: {\n order: 'post',\n handler: source => onEvent?.('resolve', `Resolving ${source}...`)\n },\n load: {\n order: 'post',\n handler: id => onEvent?.('load', `Loading ${id}...`)\n },\n transform: {\n order: 'post',\n handler: (_, id) => onEvent?.('transform', `Transforming ${id}...`)\n }\n }\n}) as PluginImpl<Options>\n","import type { PluginImpl } from 'rollup'\n\ninterface Options {\n patterns?: (string | RegExp)[]\n}\n\nexport default ((options = {}) => {\n return {\n name: 'skip',\n // skip the specified files by `options.patterns`\n load(id) {\n if (\n options.patterns?.some((pattern) =>\n typeof pattern === 'string'\n ? id.includes(pattern)\n : pattern.test(id)\n )\n ) {\n return ''\n }\n }\n }\n}) as PluginImpl<Options>\n","import fs from 'node:fs'\n\nexport default function(json: Record<string, unknown>): (string | RegExp)[]\nexport default function(path?: string): (string | RegExp)[]\nexport default function(jsonOrPath: string | Record<string, unknown> = process.cwd()): (string | RegExp)[] {\n const pkg = typeof jsonOrPath === 'string'\n ? fs.existsSync(`${jsonOrPath}/package.json`)\n ? JSON.parse(fs.readFileSync(`${jsonOrPath}/package.json`, 'utf-8'))\n : {}\n : jsonOrPath\n const { dependencies = {}, peerDependencies = {}, optionalDependencies = {} } = pkg\n const external = <(string | RegExp)[]> Object\n .keys(dependencies)\n .concat(Object.keys(peerDependencies))\n .concat(Object.keys(optionalDependencies))\n return external\n .map(dep => new RegExp(`^${dep}(/.*)?$`))\n .concat([\n /^node:/\n ])\n}\n","import '../rollup/base'\n\nimport fs from 'node:fs'\nimport { dirname, resolve } from 'node:path'\n\nimport type { Entrypoints2ExportsOptions, RecursiveRecord } from '@jiek/pkger/entrypoints'\nimport {\n DEFAULT_SKIP_VALUES,\n entrypoints2Exports,\n filterLeafs,\n getAllLeafs,\n resolveEntrypoints\n} from '@jiek/pkger/entrypoints'\nimport { dts } from '@jiek/rollup-plugin-dts'\nimport { getWorkspaceDir } from '@jiek/utils/getWorkspaceDir'\nimport json from '@rollup/plugin-json'\nimport { nodeResolve } from '@rollup/plugin-node-resolve'\nimport terser from '@rollup/plugin-terser'\nimport { sendMessage } from 'execa'\nimport { parse } from 'jsonc-parser'\nimport { isMatch } from 'micromatch'\nimport type { OutputOptions, OutputPlugin, RollupOptions } from 'rollup'\nimport esbuild from 'rollup-plugin-esbuild'\nimport ts from 'typescript'\n\nimport { loadConfig } from '../utils/loadConfig'\nimport type { RollupProgressEvent, TemplateOptions } from './base'\nimport progress from './plugins/progress'\nimport skip from './plugins/skip'\nimport externalResolver from './utils/externalResolver'\n\ninterface PackageJSON {\n name?: string\n type?: string\n exports?: Record<string, unknown> | string | string[]\n}\n\nconst {\n JIEK_ROOT,\n JIEK_ENTRIES\n} = process.env\nconst WORKSPACE_ROOT = JIEK_ROOT ?? getWorkspaceDir()\nconst COMMON_OPTIONS = {} satisfies RollupOptions\nconst COMMON_PLUGINS = [\n json()\n]\n\nconst { build } = loadConfig()\nconst jsOutdir = resolve(\n (\n typeof build?.output?.dir === 'object'\n // the outdir only effect js output in this function\n ? build.output.dir.js\n : build?.output?.dir\n ) ?? 'dist'\n)\n\nconst STYLE_REGEXP = /\\.(css|s[ac]ss|less|styl)$/\n\n// eslint-disable-next-line unused-imports/no-unused-vars\nconst debug = (...args: unknown[]) => sendMessage({ type: 'debug', data: args } satisfies RollupProgressEvent)\n\nconst resolveWorkspacePath = (p: string) => resolve(WORKSPACE_ROOT, p)\n\nconst intersection = <T>(a: Set<T>, b: Set<T>) => new Set([...a].filter(i => b.has(i)))\n\nconst pascalCase = (str: string) =>\n str\n .replace(/[@|/-](\\w)/g, (_, $1) => $1.toUpperCase())\n .replace(/(?:^|-)(\\w)/g, (_, $1) => $1.toUpperCase())\n\nconst reveal = (obj: string | Record<string, unknown>, keys: string[]) =>\n keys.reduce((acc, key) => {\n if (typeof acc === 'string') throw new Error('key not found in exports')\n if (!(key in acc)) throw new Error(`key ${key} not found in exports`)\n return acc[key] as string | Record<string, unknown>\n }, obj)\n\nconst withMinify = (\n output: OutputOptions & {\n plugins?: OutputPlugin[]\n },\n minify = build?.output?.minify\n) =>\n minify === false\n ? [output]\n : minify === 'only-minify'\n ? [{\n ...output,\n // TODO replace suffix when pubish to npm and the `build.output.minify` is 'only-minify'\n // TODO resolve dts output file name\n file: output.file?.replace(/(\\.[cm]?js)$/, '.min$1'),\n plugins: [\n ...(output.plugins ?? []),\n terser()\n ]\n }]\n : [\n output,\n {\n ...output,\n file: output.file?.replace(/(\\.[cm]?js)$/, '.min$1'),\n plugins: [\n ...(output.plugins ?? []),\n terser()\n ]\n }\n ]\n\ntype TSConfig = {\n extends?: string | string[]\n compilerOptions?: Record<string, unknown>\n references?: { path: string }[]\n files?: string[]\n include?: string[]\n exclude?: string[]\n}\n\nconst getTSConfig = (p: string): TSConfig =>\n !fs.existsSync(p) || !fs.statSync(p).isFile()\n ? {}\n : parse(fs.readFileSync(p, 'utf-8'), [], { allowTrailingComma: true, allowEmptyContent: true })\n\nconst getExtendTSConfig = (tsconfigPath: string): TSConfig => {\n tsconfigPath = resolve(tsconfigPath)\n const tsconfigPathDirname = dirname(tsconfigPath)\n const { extends: exts, ...tsconfig } = getTSConfig(tsconfigPath)\n const resolvePaths = (paths: string[] | undefined) => paths?.map(p => resolve(tsconfigPathDirname, p)) ?? []\n\n const extendsPaths = resolvePaths(\n exts ? Array.isArray(exts) ? exts : [exts] : []\n )\n if (extendsPaths.length === 0) return tsconfig\n return extendsPaths\n .map(getExtendTSConfig)\n // https://www.typescriptlang.org/tsconfig/#files:~:text=Currently%2C%20the%20only%20top%2Dlevel%20property%20that%20is%20excluded%20from%20inheritance%20is%20references.\n // Currently, the only top-level property that is excluded from inheritance is references.\n .reduce((acc, { compilerOptions = {}, references: _, ...curr }) => ({\n ...acc,\n ...curr,\n compilerOptions: {\n ...acc.compilerOptions,\n ...compilerOptions\n }\n }), tsconfig)\n}\n\nconst getCompilerOptionsByFilePath = (tsconfigPath: string, filePath: string): Record<string, unknown> | undefined => {\n tsconfigPath = resolve(tsconfigPath)\n filePath = resolve(filePath)\n const tsconfigPathDirname = dirname(tsconfigPath)\n // https://www.typescriptlang.org/tsconfig/#files:~:text=It%E2%80%99s%20worth%20noting%20that%20files%2C%20include%2C%20and%20exclude%20from%20the%20inheriting%20config%20file%20overwrite%20those%20from%20the%20base%20config%20file%2C%20and%20that%20circularity%20between%20configuration%20files%20is%20not%20allowed.\n // It’s worth noting that files, include, and exclude from the inheriting config file overwrite\n // those from the base config file, and that circularity between configuration files is not allowed.\n const tsconfig = getExtendTSConfig(tsconfigPath)\n\n const resolvePaths = (paths: string[] | undefined) => paths?.map(p => resolve(tsconfigPathDirname, p)) ?? []\n\n const [\n references,\n files,\n include,\n exclude\n ] = [\n tsconfig.references?.map(({ path }) => path),\n tsconfig.files,\n tsconfig.include,\n tsconfig.exclude\n ].map(resolvePaths)\n if (exclude.length > 0 && exclude.some(i => isMatch(filePath, i))) return\n\n // when files or include is not empty, the tsconfig should be ignored\n if (tsconfig.files?.length === 0 && tsconfig.include?.length === 0) return\n let isInclude = false\n isInclude ||= files.length > 0 && files.includes(filePath)\n isInclude ||= include.length > 0 && include.some(i => isMatch(filePath, i))\n if (isInclude) {\n return tsconfig.compilerOptions ?? {}\n } else {\n // when files or include is not empty, but the file is not matched, the tsconfig should be ignored\n if (\n (tsconfig.files && tsconfig.files.length > 0)\n || (tsconfig.include && tsconfig.include.length > 0)\n ) return\n }\n\n references.reverse()\n for (const ref of references) {\n const compilerOptions = getCompilerOptionsByFilePath(ref, filePath)\n if (compilerOptions) return compilerOptions\n }\n return tsconfig.compilerOptions\n}\n\nconst generateConfigs = ({\n path,\n name,\n input,\n output,\n external,\n pkgIsModule,\n conditionals\n}: {\n path: string\n name: string\n input: string\n output: string\n external: (string | RegExp)[]\n pkgIsModule: boolean\n conditionals: string[]\n}, options: TemplateOptions = {}): RollupOptions[] => {\n const isModule = conditionals.includes('import')\n const isCommonJS = conditionals.includes('require')\n const isBrowser = conditionals.includes('browser')\n const dtsTSConfigPaths = [\n resolveWorkspacePath('tsconfig.json'),\n resolveWorkspacePath('tsconfig.dts.json')\n ]\n let dtsTSConfigPath: string | undefined\n dtsTSConfigPaths.forEach(p => {\n if (fs.existsSync(p) && fs.statSync(p).isFile()) {\n dtsTSConfigPath = p\n }\n })\n let compilerOptions: ts.CompilerOptions = {}\n if (dtsTSConfigPath) {\n const jsonCompilerOptions = getCompilerOptionsByFilePath(dtsTSConfigPath, resolve(input))\n const { options, errors } = ts.convertCompilerOptionsFromJson(\n jsonCompilerOptions,\n dirname(dtsTSConfigPath)\n )\n if (errors.length > 0) {\n throw new Error(errors.map(e => e.messageText).join('\\n'))\n }\n compilerOptions = options\n }\n const exportConditions = [...conditionals, ...(compilerOptions.customConditions ?? [])]\n const throughEventProps: RollupProgressEvent & { type: 'progress' } = {\n type: 'progress',\n data: { name, path, exportConditions, input }\n }\n const outdir = options?.output?.dir\n return [\n {\n input,\n external,\n output: [\n ...withMinify({\n file: output,\n name,\n sourcemap: typeof options?.output?.sourcemap === 'object'\n ? options.output.sourcemap.js\n : options?.output?.sourcemap ?? true,\n format: isModule ? 'esm' : (\n isCommonJS ? 'cjs' : (\n isBrowser ? 'umd' : (\n pkgIsModule ? 'esm' : 'cjs'\n )\n )\n ),\n strict: typeof options?.output?.strict === 'object'\n ? options.output.strict.js\n : options?.output?.strict\n })\n ],\n plugins: [\n nodeResolve({ exportConditions }),\n import('rollup-plugin-postcss')\n .then(({ default: postcss }) =>\n postcss({\n extract: resolve(output.replace(/\\.[cm]?js$/, '.css')),\n minimize: true\n })\n )\n .catch(() => void 0),\n esbuild(),\n progress({\n onEvent: (event, message) =>\n sendMessage(\n {\n ...throughEventProps,\n data: { ...throughEventProps.data, event, message, tags: ['js'] }\n } satisfies RollupProgressEvent\n )\n })\n ]\n },\n {\n input,\n external,\n output: [\n {\n dir: resolve((typeof outdir === 'object' ? outdir.dts : outdir) ?? 'dist'),\n sourcemap: typeof options?.output?.sourcemap === 'object'\n ? options.output.sourcemap.dts\n : options?.output?.sourcemap ?? true,\n entryFileNames: () =>\n output\n .replace(`${jsOutdir}/`, '')\n .replace(/(\\.[cm]?)js$/, '.d$1ts'),\n strict: typeof options?.output?.strict === 'object'\n ? options.output.strict.dts\n : options?.output?.strict\n }\n ],\n plugins: [\n nodeResolve({ exportConditions }),\n skip({ patterns: [STYLE_REGEXP] }),\n dts({\n respectExternal: true,\n compilerOptions\n }),\n progress({\n onEvent: (event, message) =>\n sendMessage(\n {\n ...throughEventProps,\n data: { ...throughEventProps.data, event, message, tags: ['dts'] }\n } satisfies RollupProgressEvent\n )\n })\n ]\n }\n ]\n}\n\nexport function template(packageJSON: PackageJSON): RollupOptions[] {\n const { name, type, exports: entrypoints } = packageJSON\n const pkgIsModule = type === 'module'\n if (!name) throw new Error('package.json name is required')\n if (!entrypoints) throw new Error('package.json exports is required')\n\n const entries = JIEK_ENTRIES\n ?.split(',')\n .map(e => e.trim())\n .map(e => ({\n 'index': '.'\n }[e] ?? e))\n\n const {\n crossModuleConvertor = true\n } = build ?? {}\n\n const packageName = pascalCase(name)\n\n const external = externalResolver(packageJSON as Record<string, unknown>)\n\n const [, resolvedEntrypoints] = resolveEntrypoints(entrypoints)\n if (entries) {\n Object\n .entries(resolvedEntrypoints)\n .forEach(([key]) => {\n if (!entries.some(e => isMatch(key, e, { matchBase: true }))) {\n delete resolvedEntrypoints[key]\n }\n })\n }\n const filteredResolvedEntrypoints = filterLeafs(\n resolvedEntrypoints as RecursiveRecord<string>,\n {\n skipValue: [\n // ignore values that filename starts with `.jk-noentry`\n /(^|\\/)\\.jk-noentry/,\n ...DEFAULT_SKIP_VALUES\n ]\n }\n )\n const crossModuleWithConditional: Entrypoints2ExportsOptions['withConditional'] = crossModuleConvertor\n ? {\n import: opts =>\n !pkgIsModule && intersection(\n new Set(opts.conditionals),\n new Set(['import', 'module'])\n ).size === 0\n ? opts.dist.replace(/\\.js$/, '.mjs')\n : false,\n require: opts => {\n return pkgIsModule && intersection(\n new Set(opts.conditionals),\n new Set(['require', 'node'])\n ).size === 0\n ? opts.dist.replace(/\\.js$/, '.cjs')\n : false\n }\n }\n : {}\n const exports = entrypoints2Exports(filteredResolvedEntrypoints, {\n outdir: jsOutdir,\n withConditional: {\n ...crossModuleWithConditional\n }\n })\n\n const leafMap = new Map<string, string[][]>()\n getAllLeafs(filteredResolvedEntrypoints as RecursiveRecord<string>, ({ keys, value }) => {\n if (typeof value === 'string') {\n const keysArr = leafMap.get(value) ?? []\n leafMap.set(value, keysArr)\n keysArr.push(keys)\n }\n return false\n })\n\n const configs: RollupOptions[] = []\n leafMap.forEach((keysArr, input) =>\n keysArr.forEach((keys) => {\n const [path, ...conditionals] = keys\n\n const name = packageName + (path === '.' ? '' : pascalCase(path))\n const keyExports = reveal(exports, keys)\n const commonOptions = {\n path,\n name,\n input,\n external,\n pkgIsModule\n }\n\n switch (typeof keyExports) {\n case 'string': {\n configs.push(...generateConfigs({\n ...commonOptions,\n output: keyExports,\n conditionals\n }, build))\n break\n }\n case 'object': {\n getAllLeafs(keyExports as RecursiveRecord<string>, ({ keys: nextKeys, value }) => {\n const allConditionals = [...new Set([...conditionals, ...nextKeys])]\n if (typeof value === 'string') {\n configs.push(...generateConfigs({\n ...commonOptions,\n output: value,\n conditionals: allConditionals\n }, build))\n }\n return false\n })\n break\n }\n }\n })\n )\n sendMessage(\n {\n type: 'init',\n data: {\n leafMap,\n targetsLength: configs.length\n }\n } satisfies RollupProgressEvent\n )\n return configs.map(c => ({\n ...COMMON_OPTIONS,\n ...c,\n plugins: [\n ...COMMON_PLUGINS,\n c.plugins\n ]\n }))\n}\n"],"names":["program","isWorkspaceDir","getWorkspaceDir","load","resolve","parse","dirname","isMatch","path","options","nodeResolve","sendMessage","dts","entrypoints","resolveEntrypoints","filterLeafs","DEFAULT_SKIP_VALUES","entryp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AAAA,IACH,GAAG,CAAA;AAAA,IACH,OAAS,EAAA;AAAA,MACP,GAAG,cAAA;AAAA,MACH,CAAE,CAAA,OAAA;AAAA,KACJ;AAAA,GACA,CAAA,CAAA,CAAA;AACJ;;;;"}
@@ -0,0 +1 @@
1
+ "use strict";var e=require("node:fs"),t=require("node:path"),r=require("@jiek/pkger/entrypoints"),s=require("@jiek/rollup-plugin-dts"),o=require("@jiek/utils/getWorkspaceDir"),n=require("@rollup/plugin-json"),i=require("@rollup/plugin-node-resolve"),c=require("@rollup/plugin-terser"),p=require("execa"),u=require("jsonc-parser"),a=require("micromatch"),l=require("rollup-plugin-esbuild"),d=require("typescript"),f=require("commander"),m=require("js-yaml");require("@pnpm/filter-workspace-packages");const g=(e,t)=>new Set([...e].filter((e=>t.has(e))));let y;function h(){if(y)return y;const e=f.program.getOptionValue("root");return y=e?t.isAbsolute(e)?e:t.resolve(process.cwd(),e):void 0,y}let v,w="";try{require.resolve("@pnpm/filter-workspace-packages"),w="pnpm"}catch{}""!==w&&f.program.option("-f, --filter <filter>","filter packages");let j,k=!1;function $(e){try{return require.resolve(e),!0}catch(e){return!1}}const E=[process.env.JIEK_TS_REGISTER,"esbuild-register","@swc-node/register","ts-node/register"].filter(Boolean);for(const e of E)if($(e)){j=e;break}let b="jiek.config";var q=(e={})=>{const{onEvent:t}=e;return{name:"progress",buildStart:()=>t?.("start","Start building..."),buildEnd:()=>t?.("end","Build completed!"),resolveId:{order:"post",handler:e=>t?.("resolve",`Resolving ${e}...`)},load:{order:"post",handler:e=>t?.("load",`Loading ${e}...`)},transform:{order:"post",handler:(e,r)=>t?.("transform",`Transforming ${r}...`)}}},x=(e={})=>({name:"skip",load(t){if(e.patterns?.some((e=>"string"==typeof e?t.includes(e):e.test(t))))return""}});const{JIEK_ROOT:S,JIEK_ENTRIES:O}=process.env,I=S??o.getWorkspaceDir(),M={},C=[n()],F=function(r){const{wd:s}=function(){if(v)return{wd:v,notWorkspace:k};const e=h();if(void 0!==e){const t=o.isWorkspaceDir(e,w);return k=!t,v=e,{wd:v,notWorkspace:k}}try{v=o.getWorkspaceDir(w)}catch(t){if(!("message"in t)||"workspace root not found"!==t.message)throw t;v=e,k=!0}return{wd:v,notWorkspace:k}}();let n=f.program.getOptionValue("configPath");if(n){if(!e.existsSync(n))throw new Error(`config file not found: ${n}`);t.isAbsolute(n)||(n=t.resolve(s,n))}else n=function(r,s){const o=!!j;function n(o){const n=[t.resolve(process.cwd(),`${b}.${o}`),t.resolve(process.cwd(),`.${b}.${o}`),t.resolve(r,`${b}.${o}`),t.resolve(r,`.${b}.${o}`)];s&&n.unshift(t.resolve(s,`${b}.${o}`),t.resolve(s,`.${b}.${o}`));for(const t of n)if(e.existsSync(t)&&e.lstatSync(t).isFile())return t}return b=n("js")??b,b=n("json")??b,b=n("yaml")??b,o&&(b=n("ts")??b),t.resolve(r,b)}(s,r);const i=t.extname(n);let c;switch(i){case".js":c=require(n);break;case".json":return require(n);case".yaml":return m.load(e.readFileSync(n,"utf-8"));case".ts":if(j){require(j),c=require(n);break}throw new Error("ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register");case".config":c={};break;default:throw new Error(`unsupported config file type: ${i}`)}if(!c)throw new Error("config file is empty");return c.default??c}()??{},{build:R={}}=F,T=`./${t.relative(process.cwd(),t.resolve(("object"==typeof R?.output?.dir?R.output.dir.js:R?.output?.dir)??"dist"))}`,A=/\.(css|s[ac]ss|less|styl)$/,_=e=>t.resolve(I,e),D=e=>e.replace(/[@|/-](\w)/g,((e,t)=>t.toUpperCase())).replace(/(?:^|-)(\w)/g,((e,t)=>t.toUpperCase())),L=(e,t=R?.output?.minify)=>!1===t?[e]:"only-minify"===t?[{...e,file:e.file?.replace(/(\.[cm]?js)$/,".min$1"),plugins:[...e.plugins??[],c()]}]:[e,{...e,file:e.file?.replace(/(\.[cm]?js)$/,".min$1"),plugins:[...e.plugins??[],c()]}],W=r=>{r=t.resolve(r);const s=t.dirname(r),{extends:o,...n}=(i=r,e.existsSync(i)&&e.statSync(i).isFile()?u.parse(e.readFileSync(i,"utf-8"),[],{allowTrailingComma:!0,allowEmptyContent:!0}):{});var i;const c=(p=o?Array.isArray(o)?o:[o]:[],p?.map((e=>t.resolve(s,e)))??[]);var p;return 0===c.length?n:c.map(W).reduce(((e,{compilerOptions:t={},references:r,...s})=>({...e,...s,compilerOptions:{...e.compilerOptions,...t}})),n)},J=(e,r)=>{e=t.resolve(e),r=t.resolve(r);const s=t.dirname(e),o=W(e),[n,i,c,p]=[o.references?.map((({path:e})=>e)),o.files,o.include,o.exclude].map((e=>e?.map((e=>t.resolve(s,e)))??[]));if(p.length>0&&p.some((e=>a.isMatch(r,e))))return;if(0===o.files?.length&&0===o.include?.length)return;let u=!1;if(u||(u=i.length>0&&i.includes(r)),u||(u=c.length>0&&c.some((e=>a.isMatch(r,e)))),u)return o.compilerOptions??{};if(!(o.files&&o.files.length>0||o.include&&o.include.length>0)){n.reverse();for(const e of n){const t=J(e,r);if(t)return t}return o.compilerOptions}},K=({path:r,name:o,input:n,output:c,external:u,pkgIsModule:a,conditionals:f},m={})=>{const g=f.includes("import"),y=f.includes("require"),h=f.includes("browser");let v;[_("tsconfig.json"),_("tsconfig.dts.json")].forEach((t=>{e.existsSync(t)&&e.statSync(t).isFile()&&(v=t)}));let w={};if(v){const e=J(v,t.resolve(n)),{options:r,errors:s}=d.convertCompilerOptionsFromJson(e,t.dirname(v));if(s.length>0)throw new Error(s.map((e=>e.messageText)).join("\n"));w=r}const j=[...f,...w.customConditions??[]],k={type:"progress",data:{name:o,path:r,exportConditions:j,input:n}},$=m?.output?.dir;return[{input:n,external:u,output:[...L({file:c,name:o,sourcemap:"object"==typeof m?.output?.sourcemap?m.output.sourcemap.js:m?.output?.sourcemap,format:g?"esm":y?"cjs":h?"umd":a?"esm":"cjs",strict:"object"==typeof m?.output?.strict?m.output.strict.js:m?.output?.strict})],plugins:[i.nodeResolve({exportConditions:j}),import("rollup-plugin-postcss").then((({default:e})=>e({extract:t.resolve(c.replace(/\.[cm]?js$/,".css")),minimize:!0}))).catch((()=>{})),l(),q({onEvent:(e,t)=>p.sendMessage({...k,data:{...k.data,event:e,message:t,tags:["js"]}})})]},{input:n,external:u,output:[{dir:t.resolve(("object"==typeof $?$.dts:$)??"dist"),sourcemap:"object"==typeof m?.output?.sourcemap?m.output.sourcemap.dts:m?.output?.sourcemap,entryFileNames:()=>c.replace(`${T}/`,"").replace(/(\.[cm]?)js$/,".d$1ts"),strict:"object"==typeof m?.output?.strict?m.output.strict.dts:m?.output?.strict}],plugins:[i.nodeResolve({exportConditions:j}),x({patterns:[A]}),s.dts({respectExternal:!0,compilerOptions:w}),q({onEvent:(e,t)=>p.sendMessage({...k,data:{...k.data,event:e,message:t,tags:["dts"]}})})]}]};exports.template=function(s){const{name:o,type:n,exports:i}=s,c="module"===n;if(!o)throw new Error("package.json name is required");if(!i)throw new Error("package.json exports is required");const u=O?.split(",").map((e=>e.trim())).map((e=>({index:"."}[e]??e))),l=D(o),d=function(t=process.cwd()){const r="string"==typeof t?e.existsSync(`${t}/package.json`)?JSON.parse(e.readFileSync(`${t}/package.json`,"utf-8")):{}:t,{dependencies:s={},peerDependencies:o={},optionalDependencies:n={}}=r;return Object.keys(s).concat(Object.keys(o)).concat(Object.keys(n)).map((e=>new RegExp(`^${e}(/.*)?$`))).concat([/^node:/])}(s),[f,m]=function({entrypoints:e,pkgIsModule:s,entries:o,config:n,dir:i,noFilter:c}){const{build:p={}}=n??{},{crossModuleConvertor:u=!0}=p,l=`./${d=((...e)=>t.resolve(i??process.cwd(),...e))(("object"==typeof p?.output?.dir?p.output.dir.js:p?.output?.dir)??"dist"),t.relative(i??process.cwd(),d)}`;var d;const[,f]=r.resolveEntrypoints(e);o&&Object.entries(f).forEach((([e])=>{o.some((t=>a.isMatch(e,t,{matchBase:!0})))||delete f[e]}));const m=c?f:r.filterLeafs(f,{skipValue:[/(^|\/)\.jk-noentry/,...r.DEFAULT_SKIP_VALUES]}),y=u?{import:e=>!s&&0===g(new Set(e.conditionals),new Set(["import","module"])).size&&e.dist.replace(/\.js$/,".mjs"),require:e=>!(!s||0!==g(new Set(e.conditionals),new Set(["require","node"])).size)&&e.dist.replace(/\.js$/,".cjs")}:{};return[m,r.entrypoints2Exports(m,{outdir:l,withConditional:{...y}})]}({entrypoints:i,pkgIsModule:c,entries:u,config:F}),y=new Map;r.getAllLeafs(f,(({keys:e,value:t})=>{if("string"==typeof t){const r=y.get(t)??[];y.set(t,r),r.push(e)}return!1}));const h=[];return y.forEach(((e,t)=>e.forEach((e=>{const[s,...o]=e,n=l+("."===s?"":D(s)),i=((e,t)=>t.reduce(((e,t)=>{if("string"==typeof e)throw new Error("key not found in exports");if(!(t in e))throw new Error(`key ${t} not found in exports`);return e[t]}),e))(m,e),p={path:s,name:n,input:t,external:d,pkgIsModule:c};switch(typeof i){case"string":h.push(...K({...p,output:i,conditionals:o},R));break;case"object":r.getAllLeafs(i,(({keys:e,value:t})=>{const r=[...new Set([...o,...e])];return"string"==typeof t&&h.push(...K({...p,output:t,conditionals:r},R)),!1}))}})))),p.sendMessage({type:"init",data:{leafMap:y,targetsLength:h.length}}),h.map((e=>({...M,...e,plugins:[...C,e.plugins]})))};