@deot/dev-builder 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -11,6 +11,8 @@ const chalk = require('chalk');
11
11
  const ora = require('ora');
12
12
  const node_url = require('node:url');
13
13
  const vite = require('vite');
14
+ const sharedVueConfig = require('@deot/dev-vue');
15
+ const sharedReactConfig = require('@deot/dev-react');
14
16
  const sass = require('sass');
15
17
  const postcss = require('postcss');
16
18
  const atImport = require('postcss-import');
@@ -45,11 +47,19 @@ const dirname$1 = path__namespace.dirname(node_url.fileURLToPath((typeof documen
45
47
  const run$3 = async (options) => {
46
48
  const locals = devShared.Locals.impl();
47
49
  const { cwd, workspace } = locals;
48
- const { packageName, packageDir, packageOptions, commandOptions } = options || {};
49
- const { scriptFormats, nodePackage } = commandOptions;
50
+ const {
51
+ packageSourceDir: srcDir,
52
+ packageOutDir: outDir,
53
+ packageName,
54
+ packageDir,
55
+ packageOptions,
56
+ commandOptions,
57
+ isNodePackage,
58
+ isVuePackage,
59
+ isReactPackage
60
+ } = options || {};
61
+ const { scriptFormats } = commandOptions;
50
62
  const stats = [];
51
- const srcDir = path__namespace.resolve(packageDir, "./src");
52
- const outDir = path__namespace.resolve(packageDir, "./dist");
53
63
  let files = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index\.(.*)\.?(t|j)s$/.test(i)) : [];
54
64
  if (!files.length)
55
65
  return stats;
@@ -60,6 +70,7 @@ const run$3 = async (options) => {
60
70
  workspace,
61
71
  packageName,
62
72
  packageDir,
73
+ packageSourceDir: srcDir,
63
74
  packageOptions
64
75
  }));
65
76
  let options$ = {
@@ -73,13 +84,13 @@ const run$3 = async (options) => {
73
84
  options$.configFile = path__namespace.relative(cwd, path__namespace.resolve(cwd, "./build.config.ts"));
74
85
  } else {
75
86
  options$.configFile = path__namespace.relative(cwd, path__namespace.resolve(dirname$1, "../shared.config.ts"));
87
+ options$ = isVuePackage ? vite.mergeConfig(sharedVueConfig, options$) : isReactPackage ? vite.mergeConfig(sharedReactConfig, options$) : options$;
76
88
  }
77
89
  let viteBuild = await vite.build(options$);
78
90
  return viteBuild;
79
91
  };
80
- const needFilter = typeof nodePackage === "string" && (nodePackage === "*" || nodePackage.split(",").includes(packageName));
81
92
  const formats = scriptFormats.split(",").filter((i) => {
82
- return !needFilter || ["es", "cjs"].includes(i);
93
+ return !isNodePackage || ["es", "cjs"].includes(i);
83
94
  });
84
95
  await formats.reduce(
85
96
  (preProcess, format) => {
@@ -114,8 +125,7 @@ const run$3 = async (options) => {
114
125
  };
115
126
 
116
127
  const run$2 = async (options) => {
117
- const { packageDir } = options || {};
118
- const srcDir = path__namespace.resolve(packageDir, "./src");
128
+ const { packageSourceDir: srcDir, packageOutDir: outDir } = options || {};
119
129
  const styles = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index\.(.*)\.?s?css$/.test(i)) : [];
120
130
  const stats = [];
121
131
  await styles.reduce(
@@ -125,7 +135,7 @@ const run$2 = async (options) => {
125
135
  const data = sass__namespace.compile(filepath, { style: "compressed" });
126
136
  return postcss().use(atImport()).use(atUrl()).use(flexBugs()).use(cssnano()).use(autoprefixer({ remove: false })).process(data.css, { from: filepath });
127
137
  }).then((source) => {
128
- let output = path__namespace.resolve(packageDir, `./dist/${file.replace(/\.scss$/g, ".css")}`);
138
+ let output = path__namespace.resolve(outDir, `${file.replace(/\.scss$/g, ".css")}`);
129
139
  fs.outputFileSync(output, source.css);
130
140
  return fs.stat(output);
131
141
  }).then((stat) => {
@@ -143,11 +153,11 @@ const run$2 = async (options) => {
143
153
 
144
154
  const dirname = path__namespace.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href))));
145
155
  const run$1 = async (options) => {
146
- const { workspace } = devShared.Locals.impl();
147
- const { packageDir, packageFolderName, packageOptions, commandOptions } = options;
156
+ const { workspace, packageDir: packageRootDir } = devShared.Locals.impl();
157
+ const { isVuePackage, packageDir, packageOutDir, packageSourceDir, packageOptions, commandOptions } = options;
148
158
  const done = () => {
149
159
  const stats = [];
150
- let fullpath = `${packageDir}/dist/index.d.ts`;
160
+ let fullpath = `${packageOutDir}/index.d.ts`;
151
161
  if (fs.existsSync(fullpath)) {
152
162
  let stat = fs.statSync(fullpath);
153
163
  stats.push({
@@ -166,25 +176,26 @@ const run$1 = async (options) => {
166
176
  });
167
177
  return done();
168
178
  }
169
- let tempDir = `${packageDir}/dist/temp`;
179
+ let tempDir = `${packageOutDir}/temp`;
170
180
  let rootDir = path__namespace.relative(tempDir, process.cwd());
171
181
  fs.outputFileSync(`${tempDir}/tsconfig.json`, JSON.stringify({
172
182
  extends: `${rootDir}/tsconfig.json`,
173
183
  compilerOptions: {
174
184
  declaration: true,
175
185
  emitDeclarationOnly: true,
186
+ allowJs: true,
176
187
  rootDir,
177
188
  outDir: "."
178
189
  },
179
190
  include: [
180
- path__namespace.relative(tempDir, path__namespace.resolve(packageDir, `src/*`))
191
+ path__namespace.relative(tempDir, path__namespace.resolve(packageSourceDir, `*`))
181
192
  ]
182
193
  }, null, " "));
183
- await devShared.Shell.spawn("tsc", ["-p", `${tempDir}/tsconfig.json`]);
194
+ await devShared.Shell.spawn(isVuePackage ? "vue-tsc" : "tsc", ["-p", `${tempDir}/tsconfig.json`]);
184
195
  const configPath = `${tempDir}/api-extractor.json`;
185
196
  fs.outputFileSync(configPath, JSON.stringify({
186
197
  extends: path__namespace.relative(tempDir, path__namespace.resolve(dirname, "../api-extractor.shared.json")),
187
- mainEntryPointFilePath: `.${workspace ? "/packages/" : ""}${packageFolderName}/src/index.d.ts`,
198
+ mainEntryPointFilePath: (workspace ? `./${workspace}/` : "./") + path__namespace.relative(packageRootDir, `${packageSourceDir}/index.d.ts`),
188
199
  // workspace、时以temp/packages/*/src结构,否则APIExtractor会报错
189
200
  dtsRollup: {
190
201
  publicTrimmedFilePath: "../index.d.ts"
@@ -220,7 +231,7 @@ const run$1 = async (options) => {
220
231
  );
221
232
  process.exitCode = 1;
222
233
  }
223
- await fs.remove(`${packageDir}/dist/temp`);
234
+ await fs.remove(tempDir);
224
235
  return done();
225
236
  };
226
237
 
@@ -229,29 +240,38 @@ class Build {
229
240
  packageDir;
230
241
  packageFolderName;
231
242
  packageSourceDir;
243
+ packageOutDir;
232
244
  packageName;
233
245
  packageOptions;
234
246
  commandOptions;
247
+ isVuePackage;
248
+ isReactPackage;
249
+ isNodePackage;
235
250
  constructor(packageFolderName, commandOptions) {
236
- const { workspace, packageDir, packageName, packageFolderName: packageFolderName$ } = devShared.Locals.impl();
251
+ const { workspace, packageDir, packageName, packageFolderName: packageFolderName$, subpackagesMap } = devShared.Locals.impl();
252
+ const subpackages = subpackagesMap[packageFolderName] || [];
237
253
  this.packageFolderName = packageFolderName || "";
238
254
  this.packageDir = path__namespace.resolve(packageDir, workspace ? `./${packageFolderName}` : "");
239
- this.packageSourceDir = path__namespace.resolve(packageDir, "./src");
255
+ this.packageSourceDir = path__namespace.resolve(this.packageDir, subpackages.length ? "" : "./src");
256
+ this.packageOutDir = path__namespace.resolve(this.packageDir, "./dist");
240
257
  this.packageName = packageFolderName === packageFolderName$ ? packageName : `${packageName}-${packageFolderName}`;
241
258
  this.packageOptions = require$(`${this.packageDir}/package.json`);
242
259
  this.commandOptions = commandOptions;
260
+ const { reactPackage, vuePackage, nodePackage } = commandOptions;
261
+ this.isVuePackage = typeof vuePackage === "string" && (vuePackage === "*" || vuePackage.split(",").includes(this.packageName));
262
+ this.isReactPackage = typeof vuePackage === "string" && (vuePackage === "*" || reactPackage.split(",").includes(this.packageName));
263
+ this.isNodePackage = typeof nodePackage === "string" && (nodePackage === "*" || nodePackage.split(",").includes(this.packageName));
243
264
  }
244
265
  async process() {
245
266
  let start = Date.now();
246
267
  const { cwd, workspace } = devShared.Locals.impl();
247
- const { packageOptions, packageName, packageDir } = this;
268
+ const { packageSourceDir: srcDir, packageOptions, packageName, packageDir } = this;
248
269
  if (workspace && packageOptions?.scripts?.build && packageDir !== cwd) {
249
270
  await devShared.Shell.spawn(`npm`, ["run", "build"], {
250
271
  cwd: packageDir
251
272
  });
252
273
  return;
253
274
  }
254
- const srcDir = path__namespace.resolve(packageDir, "./src");
255
275
  let files = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index(.*)\.(ts|js|s?css)$/.test(i)) : [];
256
276
  if (!files.length)
257
277
  return;
@@ -296,9 +316,6 @@ const run = (options) => devShared.Utils.autoCatch(async () => {
296
316
  ...options
297
317
  };
298
318
  const locals = devShared.Locals.impl();
299
- if (typeof options.dryRun === "undefined") {
300
- options.dryRun = process.env.NODE_ENV === "UNIT";
301
- }
302
319
  let packageFolderName = devShared.Locals.getPackageFolderName(options.packageName || "*");
303
320
  let inputs = [];
304
321
  if (locals.workspace && packageFolderName === "*") {
package/dist/index.es.js CHANGED
@@ -6,7 +6,9 @@ import fs$1 from 'fs-extra';
6
6
  import chalk from 'chalk';
7
7
  import ora from 'ora';
8
8
  import { fileURLToPath } from 'node:url';
9
- import { build as build$1 } from 'vite';
9
+ import { mergeConfig, build as build$1 } from 'vite';
10
+ import sharedVueConfig from '@deot/dev-vue';
11
+ import sharedReactConfig from '@deot/dev-react';
10
12
  import * as sass from 'sass';
11
13
  import postcss from 'postcss';
12
14
  import atImport from 'postcss-import';
@@ -20,11 +22,19 @@ const dirname$1 = path.dirname(fileURLToPath(import.meta.url));
20
22
  const run$3 = async (options) => {
21
23
  const locals = Locals.impl();
22
24
  const { cwd, workspace } = locals;
23
- const { packageName, packageDir, packageOptions, commandOptions } = options || {};
24
- const { scriptFormats, nodePackage } = commandOptions;
25
+ const {
26
+ packageSourceDir: srcDir,
27
+ packageOutDir: outDir,
28
+ packageName,
29
+ packageDir,
30
+ packageOptions,
31
+ commandOptions,
32
+ isNodePackage,
33
+ isVuePackage,
34
+ isReactPackage
35
+ } = options || {};
36
+ const { scriptFormats } = commandOptions;
25
37
  const stats = [];
26
- const srcDir = path.resolve(packageDir, "./src");
27
- const outDir = path.resolve(packageDir, "./dist");
28
38
  let files = fs$1.existsSync(srcDir) ? fs$1.readdirSync(srcDir).filter((i) => /^index\.(.*)\.?(t|j)s$/.test(i)) : [];
29
39
  if (!files.length)
30
40
  return stats;
@@ -35,6 +45,7 @@ const run$3 = async (options) => {
35
45
  workspace,
36
46
  packageName,
37
47
  packageDir,
48
+ packageSourceDir: srcDir,
38
49
  packageOptions
39
50
  }));
40
51
  let options$ = {
@@ -48,13 +59,13 @@ const run$3 = async (options) => {
48
59
  options$.configFile = path.relative(cwd, path.resolve(cwd, "./build.config.ts"));
49
60
  } else {
50
61
  options$.configFile = path.relative(cwd, path.resolve(dirname$1, "../shared.config.ts"));
62
+ options$ = isVuePackage ? mergeConfig(sharedVueConfig, options$) : isReactPackage ? mergeConfig(sharedReactConfig, options$) : options$;
51
63
  }
52
64
  let viteBuild = await build$1(options$);
53
65
  return viteBuild;
54
66
  };
55
- const needFilter = typeof nodePackage === "string" && (nodePackage === "*" || nodePackage.split(",").includes(packageName));
56
67
  const formats = scriptFormats.split(",").filter((i) => {
57
- return !needFilter || ["es", "cjs"].includes(i);
68
+ return !isNodePackage || ["es", "cjs"].includes(i);
58
69
  });
59
70
  await formats.reduce(
60
71
  (preProcess, format) => {
@@ -89,8 +100,7 @@ const run$3 = async (options) => {
89
100
  };
90
101
 
91
102
  const run$2 = async (options) => {
92
- const { packageDir } = options || {};
93
- const srcDir = path.resolve(packageDir, "./src");
103
+ const { packageSourceDir: srcDir, packageOutDir: outDir } = options || {};
94
104
  const styles = fs$1.existsSync(srcDir) ? fs$1.readdirSync(srcDir).filter((i) => /^index\.(.*)\.?s?css$/.test(i)) : [];
95
105
  const stats = [];
96
106
  await styles.reduce(
@@ -100,7 +110,7 @@ const run$2 = async (options) => {
100
110
  const data = sass.compile(filepath, { style: "compressed" });
101
111
  return postcss().use(atImport()).use(atUrl()).use(flexBugs()).use(cssnano()).use(autoprefixer({ remove: false })).process(data.css, { from: filepath });
102
112
  }).then((source) => {
103
- let output = path.resolve(packageDir, `./dist/${file.replace(/\.scss$/g, ".css")}`);
113
+ let output = path.resolve(outDir, `${file.replace(/\.scss$/g, ".css")}`);
104
114
  fs$1.outputFileSync(output, source.css);
105
115
  return fs$1.stat(output);
106
116
  }).then((stat) => {
@@ -118,11 +128,11 @@ const run$2 = async (options) => {
118
128
 
119
129
  const dirname = path.dirname(fileURLToPath(import.meta.url));
120
130
  const run$1 = async (options) => {
121
- const { workspace } = Locals.impl();
122
- const { packageDir, packageFolderName, packageOptions, commandOptions } = options;
131
+ const { workspace, packageDir: packageRootDir } = Locals.impl();
132
+ const { isVuePackage, packageDir, packageOutDir, packageSourceDir, packageOptions, commandOptions } = options;
123
133
  const done = () => {
124
134
  const stats = [];
125
- let fullpath = `${packageDir}/dist/index.d.ts`;
135
+ let fullpath = `${packageOutDir}/index.d.ts`;
126
136
  if (fs$1.existsSync(fullpath)) {
127
137
  let stat = fs$1.statSync(fullpath);
128
138
  stats.push({
@@ -141,25 +151,26 @@ const run$1 = async (options) => {
141
151
  });
142
152
  return done();
143
153
  }
144
- let tempDir = `${packageDir}/dist/temp`;
154
+ let tempDir = `${packageOutDir}/temp`;
145
155
  let rootDir = path.relative(tempDir, process.cwd());
146
156
  fs$1.outputFileSync(`${tempDir}/tsconfig.json`, JSON.stringify({
147
157
  extends: `${rootDir}/tsconfig.json`,
148
158
  compilerOptions: {
149
159
  declaration: true,
150
160
  emitDeclarationOnly: true,
161
+ allowJs: true,
151
162
  rootDir,
152
163
  outDir: "."
153
164
  },
154
165
  include: [
155
- path.relative(tempDir, path.resolve(packageDir, `src/*`))
166
+ path.relative(tempDir, path.resolve(packageSourceDir, `*`))
156
167
  ]
157
168
  }, null, " "));
158
- await Shell.spawn("tsc", ["-p", `${tempDir}/tsconfig.json`]);
169
+ await Shell.spawn(isVuePackage ? "vue-tsc" : "tsc", ["-p", `${tempDir}/tsconfig.json`]);
159
170
  const configPath = `${tempDir}/api-extractor.json`;
160
171
  fs$1.outputFileSync(configPath, JSON.stringify({
161
172
  extends: path.relative(tempDir, path.resolve(dirname, "../api-extractor.shared.json")),
162
- mainEntryPointFilePath: `.${workspace ? "/packages/" : ""}${packageFolderName}/src/index.d.ts`,
173
+ mainEntryPointFilePath: (workspace ? `./${workspace}/` : "./") + path.relative(packageRootDir, `${packageSourceDir}/index.d.ts`),
163
174
  // workspace、时以temp/packages/*/src结构,否则APIExtractor会报错
164
175
  dtsRollup: {
165
176
  publicTrimmedFilePath: "../index.d.ts"
@@ -195,7 +206,7 @@ const run$1 = async (options) => {
195
206
  );
196
207
  process.exitCode = 1;
197
208
  }
198
- await fs$1.remove(`${packageDir}/dist/temp`);
209
+ await fs$1.remove(tempDir);
199
210
  return done();
200
211
  };
201
212
 
@@ -204,29 +215,38 @@ class Build {
204
215
  packageDir;
205
216
  packageFolderName;
206
217
  packageSourceDir;
218
+ packageOutDir;
207
219
  packageName;
208
220
  packageOptions;
209
221
  commandOptions;
222
+ isVuePackage;
223
+ isReactPackage;
224
+ isNodePackage;
210
225
  constructor(packageFolderName, commandOptions) {
211
- const { workspace, packageDir, packageName, packageFolderName: packageFolderName$ } = Locals.impl();
226
+ const { workspace, packageDir, packageName, packageFolderName: packageFolderName$, subpackagesMap } = Locals.impl();
227
+ const subpackages = subpackagesMap[packageFolderName] || [];
212
228
  this.packageFolderName = packageFolderName || "";
213
229
  this.packageDir = path.resolve(packageDir, workspace ? `./${packageFolderName}` : "");
214
- this.packageSourceDir = path.resolve(packageDir, "./src");
230
+ this.packageSourceDir = path.resolve(this.packageDir, subpackages.length ? "" : "./src");
231
+ this.packageOutDir = path.resolve(this.packageDir, "./dist");
215
232
  this.packageName = packageFolderName === packageFolderName$ ? packageName : `${packageName}-${packageFolderName}`;
216
233
  this.packageOptions = require$(`${this.packageDir}/package.json`);
217
234
  this.commandOptions = commandOptions;
235
+ const { reactPackage, vuePackage, nodePackage } = commandOptions;
236
+ this.isVuePackage = typeof vuePackage === "string" && (vuePackage === "*" || vuePackage.split(",").includes(this.packageName));
237
+ this.isReactPackage = typeof vuePackage === "string" && (vuePackage === "*" || reactPackage.split(",").includes(this.packageName));
238
+ this.isNodePackage = typeof nodePackage === "string" && (nodePackage === "*" || nodePackage.split(",").includes(this.packageName));
218
239
  }
219
240
  async process() {
220
241
  let start = Date.now();
221
242
  const { cwd, workspace } = Locals.impl();
222
- const { packageOptions, packageName, packageDir } = this;
243
+ const { packageSourceDir: srcDir, packageOptions, packageName, packageDir } = this;
223
244
  if (workspace && packageOptions?.scripts?.build && packageDir !== cwd) {
224
245
  await Shell.spawn(`npm`, ["run", "build"], {
225
246
  cwd: packageDir
226
247
  });
227
248
  return;
228
249
  }
229
- const srcDir = path.resolve(packageDir, "./src");
230
250
  let files = fs$1.existsSync(srcDir) ? fs$1.readdirSync(srcDir).filter((i) => /^index(.*)\.(ts|js|s?css)$/.test(i)) : [];
231
251
  if (!files.length)
232
252
  return;
@@ -271,9 +291,6 @@ const run = (options) => Utils.autoCatch(async () => {
271
291
  ...options
272
292
  };
273
293
  const locals = Locals.impl();
274
- if (typeof options.dryRun === "undefined") {
275
- options.dryRun = process.env.NODE_ENV === "UNIT";
276
- }
277
294
  let packageFolderName = Locals.getPackageFolderName(options.packageName || "*");
278
295
  let inputs = [];
279
296
  if (locals.workspace && packageFolderName === "*") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deot/dev-builder",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,14 +29,16 @@
29
29
  }
30
30
  },
31
31
  "dependencies": {
32
- "@deot/dev-shared": "^2.4.0",
32
+ "@deot/dev-react": "^2.5.0",
33
+ "@deot/dev-shared": "^2.5.0",
34
+ "@deot/dev-vue": "^2.5.0",
33
35
  "@microsoft/api-extractor": "^7.36.4",
34
36
  "autoprefixer": "^10.4.15",
35
37
  "chalk": "^5.3.0",
36
38
  "cssnano": "^6.0.1",
37
39
  "fs-extra": "^11.1.1",
38
40
  "ora": "^7.0.1",
39
- "postcss": "^8.4.28",
41
+ "postcss": "^8.4.29",
40
42
  "postcss-flexbugs-fixes": "^5.0.2",
41
43
  "postcss-import": "^15.1.0",
42
44
  "postcss-url": "^10.1.3",
package/shared.config.ts CHANGED
@@ -18,7 +18,7 @@ const {
18
18
  workspace,
19
19
  files = [],
20
20
  packageName,
21
- packageDir,
21
+ packageSourceDir,
22
22
  packageOptions = {}
23
23
  } = buildOptions;
24
24
 
@@ -73,7 +73,7 @@ export default defineConfig({
73
73
  minify: false,
74
74
  target: 'esnext',
75
75
  lib: {
76
- entry: files.map((file: string) => path.resolve(packageDir, './src', file)),
76
+ entry: files.map((file: string) => path.resolve(packageSourceDir, file)),
77
77
  formats: [format],
78
78
  name: packageName.replace(/(_|-|^|.*\/)([^-_\/@])/g, (_match: any, _$1: any, $2: string) => $2.toUpperCase())
79
79
  },