@deot/dev-builder 2.3.2 → 2.4.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.
@@ -2,8 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const devShared = require('@deot/dev-shared');
6
5
  const path = require('node:path');
6
+ const fs$1 = require('node:fs');
7
+ const devShared = require('@deot/dev-shared');
7
8
  const node_module = require('node:module');
8
9
  const fs = require('fs-extra');
9
10
  const chalk = require('chalk');
@@ -37,6 +38,7 @@ function _interopNamespaceDefault(e) {
37
38
  }
38
39
 
39
40
  const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
41
+ const fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs$1);
40
42
  const sass__namespace = /*#__PURE__*/_interopNamespaceDefault(sass);
41
43
 
42
44
  const dirname$1 = 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))));
@@ -89,7 +91,7 @@ const run$3 = async (options) => {
89
91
  return;
90
92
  }
91
93
  if (j.type === "chunk") {
92
- fs.outputFileSync(`${outDir}/${j.name}.${format}.js`, j.code);
94
+ fs.outputFileSync(`${outDir}/${j.name}.${format}${format === "cjs" ? "" : ".js"}`, j.code);
93
95
  return;
94
96
  }
95
97
  });
@@ -99,12 +101,12 @@ const run$3 = async (options) => {
99
101
  },
100
102
  Promise.resolve()
101
103
  );
102
- let outputs = fs.readdirSync(outDir).filter((i) => /^index(.*)(?!=\.d)\.js$/.test(i));
104
+ let outputs = fs.readdirSync(outDir).filter((i) => /^index(.*)(?!=\.d)\.c?js$/.test(i));
103
105
  outputs.forEach((file) => {
104
106
  let stat = fs.statSync(path__namespace.resolve(outDir, file));
105
107
  stats.push({
106
- file: file.replace(/^(.*)(\..*\.js)/, "$1.ts"),
107
- format: file.replace(/.*\.(.*)\.js/, "$1"),
108
+ file: file.replace(/^(.*)((\..*\.js)|\.cjs)/, "$1.ts"),
109
+ format: file.replace(/(.*\.(.*)\.js|.*\.(cjs))/, "$2$3"),
108
110
  size: stat.size
109
111
  });
110
112
  });
@@ -297,14 +299,33 @@ const run = (options) => devShared.Utils.autoCatch(async () => {
297
299
  if (typeof options.dryRun === "undefined") {
298
300
  options.dryRun = process.env.NODE_ENV === "UNIT";
299
301
  }
300
- const { normalizePackageFolderNames } = devShared.Locals.impl();
301
302
  let packageFolderName = devShared.Locals.getPackageFolderName(options.packageName || "*");
302
303
  let inputs = [];
303
304
  if (locals.workspace && packageFolderName === "*") {
304
- inputs = normalizePackageFolderNames;
305
+ inputs = locals.normalizePackageFolderNames;
305
306
  } else {
306
307
  inputs = [packageFolderName];
307
308
  }
309
+ if (options.packageName && options.packageName !== "*") {
310
+ let relations = [];
311
+ const walk = (packageNames) => {
312
+ relations = packageNames.concat(relations);
313
+ packageNames.forEach((i) => {
314
+ if (locals.packageRelation[i].length) {
315
+ walk(locals.packageRelation[i]);
316
+ }
317
+ });
318
+ };
319
+ walk(locals.packageRelation[options.packageName]);
320
+ relations = relations.filter((i, index, source) => source.indexOf(i) === index).map((i) => devShared.Locals.getPackageFolderName(i)).filter((i) => {
321
+ try {
322
+ return options.dryRun || !fs__namespace.existsSync(path__namespace.resolve(locals.packageDir, i, "dist"));
323
+ } catch (e) {
324
+ return false;
325
+ }
326
+ });
327
+ inputs = relations.concat(inputs);
328
+ }
308
329
  if (options.dryRun)
309
330
  return devShared.Shell.spawn(`echo ${inputs.join(" ")}`);
310
331
  await inputs.reduce(
package/dist/index.es.js CHANGED
@@ -1,7 +1,8 @@
1
- import { Locals, Shell, Logger, Utils } from '@deot/dev-shared';
2
1
  import * as path from 'node:path';
2
+ import * as fs from 'node:fs';
3
+ import { Locals, Shell, Logger, Utils } from '@deot/dev-shared';
3
4
  import { createRequire } from 'node:module';
4
- import fs from 'fs-extra';
5
+ import fs$1 from 'fs-extra';
5
6
  import chalk from 'chalk';
6
7
  import ora from 'ora';
7
8
  import { fileURLToPath } from 'node:url';
@@ -24,7 +25,7 @@ const run$3 = async (options) => {
24
25
  const stats = [];
25
26
  const srcDir = path.resolve(packageDir, "./src");
26
27
  const outDir = path.resolve(packageDir, "./dist");
27
- let files = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index\.(.*)\.?(t|j)s$/.test(i)) : [];
28
+ let files = fs$1.existsSync(srcDir) ? fs$1.readdirSync(srcDir).filter((i) => /^index\.(.*)\.?(t|j)s$/.test(i)) : [];
28
29
  if (!files.length)
29
30
  return stats;
30
31
  const build = async (format) => {
@@ -41,9 +42,9 @@ const run$3 = async (options) => {
41
42
  write: false
42
43
  }
43
44
  };
44
- if (fs.existsSync(`${cwd}/z.build.config.ts`)) {
45
+ if (fs$1.existsSync(`${cwd}/z.build.config.ts`)) {
45
46
  options$.configFile = path.relative(cwd, path.resolve(cwd, "./z.build.config.ts"));
46
- } else if (fs.existsSync(`${cwd}/build.config.ts`)) {
47
+ } else if (fs$1.existsSync(`${cwd}/build.config.ts`)) {
47
48
  options$.configFile = path.relative(cwd, path.resolve(cwd, "./build.config.ts"));
48
49
  } else {
49
50
  options$.configFile = path.relative(cwd, path.resolve(dirname$1, "../shared.config.ts"));
@@ -61,11 +62,11 @@ const run$3 = async (options) => {
61
62
  outputs2.forEach((i) => {
62
63
  i.output.forEach((j) => {
63
64
  if (j.type === "asset") {
64
- fs.outputFileSync(`${outDir}/${j.fileName}`, j.source);
65
+ fs$1.outputFileSync(`${outDir}/${j.fileName}`, j.source);
65
66
  return;
66
67
  }
67
68
  if (j.type === "chunk") {
68
- fs.outputFileSync(`${outDir}/${j.name}.${format}.js`, j.code);
69
+ fs$1.outputFileSync(`${outDir}/${j.name}.${format}${format === "cjs" ? "" : ".js"}`, j.code);
69
70
  return;
70
71
  }
71
72
  });
@@ -75,12 +76,12 @@ const run$3 = async (options) => {
75
76
  },
76
77
  Promise.resolve()
77
78
  );
78
- let outputs = fs.readdirSync(outDir).filter((i) => /^index(.*)(?!=\.d)\.js$/.test(i));
79
+ let outputs = fs$1.readdirSync(outDir).filter((i) => /^index(.*)(?!=\.d)\.c?js$/.test(i));
79
80
  outputs.forEach((file) => {
80
- let stat = fs.statSync(path.resolve(outDir, file));
81
+ let stat = fs$1.statSync(path.resolve(outDir, file));
81
82
  stats.push({
82
- file: file.replace(/^(.*)(\..*\.js)/, "$1.ts"),
83
- format: file.replace(/.*\.(.*)\.js/, "$1"),
83
+ file: file.replace(/^(.*)((\..*\.js)|\.cjs)/, "$1.ts"),
84
+ format: file.replace(/(.*\.(.*)\.js|.*\.(cjs))/, "$2$3"),
84
85
  size: stat.size
85
86
  });
86
87
  });
@@ -90,7 +91,7 @@ const run$3 = async (options) => {
90
91
  const run$2 = async (options) => {
91
92
  const { packageDir } = options || {};
92
93
  const srcDir = path.resolve(packageDir, "./src");
93
- const styles = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index\.(.*)\.?s?css$/.test(i)) : [];
94
+ const styles = fs$1.existsSync(srcDir) ? fs$1.readdirSync(srcDir).filter((i) => /^index\.(.*)\.?s?css$/.test(i)) : [];
94
95
  const stats = [];
95
96
  await styles.reduce(
96
97
  (preProcess, file) => {
@@ -100,8 +101,8 @@ const run$2 = async (options) => {
100
101
  return postcss().use(atImport()).use(atUrl()).use(flexBugs()).use(cssnano()).use(autoprefixer({ remove: false })).process(data.css, { from: filepath });
101
102
  }).then((source) => {
102
103
  let output = path.resolve(packageDir, `./dist/${file.replace(/\.scss$/g, ".css")}`);
103
- fs.outputFileSync(output, source.css);
104
- return fs.stat(output);
104
+ fs$1.outputFileSync(output, source.css);
105
+ return fs$1.stat(output);
105
106
  }).then((stat) => {
106
107
  stats.push({
107
108
  file,
@@ -122,8 +123,8 @@ const run$1 = async (options) => {
122
123
  const done = () => {
123
124
  const stats = [];
124
125
  let fullpath = `${packageDir}/dist/index.d.ts`;
125
- if (fs.existsSync(fullpath)) {
126
- let stat = fs.statSync(fullpath);
126
+ if (fs$1.existsSync(fullpath)) {
127
+ let stat = fs$1.statSync(fullpath);
127
128
  stats.push({
128
129
  file: "index.d.ts",
129
130
  size: stat.size
@@ -142,7 +143,7 @@ const run$1 = async (options) => {
142
143
  }
143
144
  let tempDir = `${packageDir}/dist/temp`;
144
145
  let rootDir = path.relative(tempDir, process.cwd());
145
- fs.outputFileSync(`${tempDir}/tsconfig.json`, JSON.stringify({
146
+ fs$1.outputFileSync(`${tempDir}/tsconfig.json`, JSON.stringify({
146
147
  extends: `${rootDir}/tsconfig.json`,
147
148
  compilerOptions: {
148
149
  declaration: true,
@@ -156,7 +157,7 @@ const run$1 = async (options) => {
156
157
  }, null, " "));
157
158
  await Shell.spawn("tsc", ["-p", `${tempDir}/tsconfig.json`]);
158
159
  const configPath = `${tempDir}/api-extractor.json`;
159
- fs.outputFileSync(configPath, JSON.stringify({
160
+ fs$1.outputFileSync(configPath, JSON.stringify({
160
161
  extends: path.relative(tempDir, path.resolve(dirname, "../api-extractor.shared.json")),
161
162
  mainEntryPointFilePath: `.${workspace ? "/packages/" : ""}${packageFolderName}/src/index.d.ts`,
162
163
  // workspace、时以temp/packages/*/src结构,否则APIExtractor会报错
@@ -194,7 +195,7 @@ const run$1 = async (options) => {
194
195
  );
195
196
  process.exitCode = 1;
196
197
  }
197
- await fs.remove(`${packageDir}/dist/temp`);
198
+ await fs$1.remove(`${packageDir}/dist/temp`);
198
199
  return done();
199
200
  };
200
201
 
@@ -226,13 +227,13 @@ class Build {
226
227
  return;
227
228
  }
228
229
  const srcDir = path.resolve(packageDir, "./src");
229
- let files = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index(.*)\.(ts|js|s?css)$/.test(i)) : [];
230
+ let files = fs$1.existsSync(srcDir) ? fs$1.readdirSync(srcDir).filter((i) => /^index(.*)\.(ts|js|s?css)$/.test(i)) : [];
230
231
  if (!files.length)
231
232
  return;
232
233
  const spinner = ora(`${packageName} Build ...`);
233
234
  try {
234
235
  spinner.start();
235
- await fs.emptyDir(`${packageDir}/dist`);
236
+ await fs$1.emptyDir(`${packageDir}/dist`);
236
237
  const scriptStats = await run$3(this);
237
238
  const scriptDuration = Date.now() - start;
238
239
  const styleStats = await run$2(this);
@@ -273,14 +274,33 @@ const run = (options) => Utils.autoCatch(async () => {
273
274
  if (typeof options.dryRun === "undefined") {
274
275
  options.dryRun = process.env.NODE_ENV === "UNIT";
275
276
  }
276
- const { normalizePackageFolderNames } = Locals.impl();
277
277
  let packageFolderName = Locals.getPackageFolderName(options.packageName || "*");
278
278
  let inputs = [];
279
279
  if (locals.workspace && packageFolderName === "*") {
280
- inputs = normalizePackageFolderNames;
280
+ inputs = locals.normalizePackageFolderNames;
281
281
  } else {
282
282
  inputs = [packageFolderName];
283
283
  }
284
+ if (options.packageName && options.packageName !== "*") {
285
+ let relations = [];
286
+ const walk = (packageNames) => {
287
+ relations = packageNames.concat(relations);
288
+ packageNames.forEach((i) => {
289
+ if (locals.packageRelation[i].length) {
290
+ walk(locals.packageRelation[i]);
291
+ }
292
+ });
293
+ };
294
+ walk(locals.packageRelation[options.packageName]);
295
+ relations = relations.filter((i, index, source) => source.indexOf(i) === index).map((i) => Locals.getPackageFolderName(i)).filter((i) => {
296
+ try {
297
+ return options.dryRun || !fs.existsSync(path.resolve(locals.packageDir, i, "dist"));
298
+ } catch (e) {
299
+ return false;
300
+ }
301
+ });
302
+ inputs = relations.concat(inputs);
303
+ }
284
304
  if (options.dryRun)
285
305
  return Shell.spawn(`echo ${inputs.join(" ")}`);
286
306
  await inputs.reduce(
package/package.json CHANGED
@@ -1,10 +1,16 @@
1
1
  {
2
2
  "name": "@deot/dev-builder",
3
- "version": "2.3.2",
3
+ "version": "2.4.0",
4
+ "type": "module",
4
5
  "main": "dist/index.es.js",
5
- "module": "dist/index.es.js",
6
6
  "types": "dist/index.d.ts",
7
- "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.es.js",
10
+ "require": "./dist/index.cjs",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
8
14
  "files": [
9
15
  "dist",
10
16
  "api-extractor.shared.json",
@@ -23,7 +29,7 @@
23
29
  }
24
30
  },
25
31
  "dependencies": {
26
- "@deot/dev-shared": "^2.3.0",
32
+ "@deot/dev-shared": "^2.4.0",
27
33
  "@microsoft/api-extractor": "^7.36.4",
28
34
  "autoprefixer": "^10.4.15",
29
35
  "chalk": "^5.3.0",
@@ -34,7 +40,7 @@
34
40
  "postcss-flexbugs-fixes": "^5.0.2",
35
41
  "postcss-import": "^15.1.0",
36
42
  "postcss-url": "^10.1.3",
37
- "sass": "^1.65.1",
43
+ "sass": "^1.66.1",
38
44
  "vite": "^4.4.9"
39
45
  },
40
46
  "devDependencies": {