@deot/dev-builder 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  打包
4
4
 
5
5
  - 优先执行`scripts`下的`build`和`build:types`,如果声明`build`,打包由用户管理,`build:types`,类型编译由用户管理
6
- - 可被打包的文件匹配:`src/index.*.(j|t|s?cs)s`
6
+ - 可被打包的文件匹配:`src/index\.(.*)\.?(j|t|s?cs)s`
7
7
 
8
8
  ## 自定义配置
9
9
 
package/dist/index.cjs.js CHANGED
@@ -38,32 +38,63 @@ function _interopNamespaceDefault(e) {
38
38
 
39
39
  const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
40
40
 
41
- 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.js', document.baseURI).href))));
41
+ 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))));
42
42
  const run$3 = async (options) => {
43
43
  const locals = devShared.Locals.impl();
44
- const { cwd } = locals;
45
- const { packageName, packageDir, packageOptions } = options || {};
44
+ const { cwd, workspace } = locals;
45
+ const { packageName, packageDir, packageOptions, commandOptions } = options || {};
46
+ const { scriptFormats } = commandOptions;
46
47
  const stats = [];
47
48
  const srcDir = path__namespace.resolve(packageDir, "./src");
48
49
  const outDir = path__namespace.resolve(packageDir, "./dist");
49
- let files = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index(.*)\.(t|j)s$/.test(i)) : [];
50
+ let files = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index\.(.*)\.?(t|j)s$/.test(i)) : [];
50
51
  if (!files.length)
51
52
  return stats;
52
- process.env.BUILD_OPTIONS = encodeURIComponent(JSON.stringify({
53
- files,
54
- packageName,
55
- packageDir,
56
- packageOptions
57
- }));
58
- let options$ = {};
59
- if (fs.existsSync(`${cwd}/build.config.ts`)) {
60
- options$.configFile = path__namespace.relative(cwd, path__namespace.resolve(cwd, "./build.config.ts"));
61
- } else if (fs.existsSync(`${cwd}/z.build.config.ts`)) {
62
- options$.configFile = path__namespace.relative(cwd, path__namespace.resolve(cwd, "./z.build.config.ts"));
63
- } else {
64
- options$.configFile = path__namespace.relative(cwd, path__namespace.resolve(dirname$1, "../shared.config.ts"));
65
- }
66
- await vite.build(options$);
53
+ const build = async (format) => {
54
+ process.env.BUILD_OPTIONS = encodeURIComponent(JSON.stringify({
55
+ files,
56
+ format,
57
+ workspace,
58
+ packageName,
59
+ packageDir,
60
+ packageOptions
61
+ }));
62
+ let options$ = {
63
+ build: {
64
+ write: false
65
+ }
66
+ };
67
+ if (fs.existsSync(`${cwd}/z.build.config.ts`)) {
68
+ options$.configFile = path__namespace.relative(cwd, path__namespace.resolve(cwd, "./z.build.config.ts"));
69
+ } else if (fs.existsSync(`${cwd}/build.config.ts`)) {
70
+ options$.configFile = path__namespace.relative(cwd, path__namespace.resolve(cwd, "./build.config.ts"));
71
+ } else {
72
+ options$.configFile = path__namespace.relative(cwd, path__namespace.resolve(dirname$1, "../shared.config.ts"));
73
+ }
74
+ let viteBuild = await vite.build(options$);
75
+ return viteBuild;
76
+ };
77
+ const formats = scriptFormats.split(",");
78
+ await formats.reduce(
79
+ (preProcess, format) => {
80
+ preProcess = preProcess.then(() => build(format)).then((outputs2) => {
81
+ outputs2.forEach((i) => {
82
+ i.output.forEach((j) => {
83
+ if (j.type === "asset") {
84
+ fs.outputFileSync(`${outDir}/${j.fileName}`, j.source);
85
+ return;
86
+ }
87
+ if (j.type === "chunk") {
88
+ fs.outputFileSync(`${outDir}/${j.name}.${format}.js`, j.code);
89
+ return;
90
+ }
91
+ });
92
+ });
93
+ });
94
+ return preProcess;
95
+ },
96
+ Promise.resolve()
97
+ );
67
98
  let outputs = fs.readdirSync(outDir).filter((i) => /^index(.*)(?!=\.d)\.js$/.test(i));
68
99
  outputs.forEach((file) => {
69
100
  let stat = fs.statSync(path__namespace.resolve(outDir, file));
@@ -79,7 +110,7 @@ const run$3 = async (options) => {
79
110
  const run$2 = async (options) => {
80
111
  const { packageDir } = options || {};
81
112
  const srcDir = path__namespace.resolve(packageDir, "./src");
82
- const styles = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index(.*)\.s?css$/.test(i)) : [];
113
+ const styles = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index\.(.*)\.?s?css$/.test(i)) : [];
83
114
  const stats = [];
84
115
  await styles.reduce(
85
116
  (preProcess, file) => {
@@ -104,7 +135,7 @@ const run$2 = async (options) => {
104
135
  return stats;
105
136
  };
106
137
 
107
- 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.js', document.baseURI).href))));
138
+ 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))));
108
139
  const run$1 = async (options) => {
109
140
  const { workspace } = devShared.Locals.impl();
110
141
  const { packageDir, packageFolderName, packageOptions, commandOptions } = options;
package/dist/index.es.js CHANGED
@@ -18,29 +18,60 @@ import { Extractor, ExtractorConfig } from '@microsoft/api-extractor';
18
18
  const dirname$1 = path.dirname(fileURLToPath(import.meta.url));
19
19
  const run$3 = async (options) => {
20
20
  const locals = Locals.impl();
21
- const { cwd } = locals;
22
- const { packageName, packageDir, packageOptions } = options || {};
21
+ const { cwd, workspace } = locals;
22
+ const { packageName, packageDir, packageOptions, commandOptions } = options || {};
23
+ const { scriptFormats } = commandOptions;
23
24
  const stats = [];
24
25
  const srcDir = path.resolve(packageDir, "./src");
25
26
  const outDir = path.resolve(packageDir, "./dist");
26
- let files = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index(.*)\.(t|j)s$/.test(i)) : [];
27
+ let files = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index\.(.*)\.?(t|j)s$/.test(i)) : [];
27
28
  if (!files.length)
28
29
  return stats;
29
- process.env.BUILD_OPTIONS = encodeURIComponent(JSON.stringify({
30
- files,
31
- packageName,
32
- packageDir,
33
- packageOptions
34
- }));
35
- let options$ = {};
36
- if (fs.existsSync(`${cwd}/build.config.ts`)) {
37
- options$.configFile = path.relative(cwd, path.resolve(cwd, "./build.config.ts"));
38
- } else if (fs.existsSync(`${cwd}/z.build.config.ts`)) {
39
- options$.configFile = path.relative(cwd, path.resolve(cwd, "./z.build.config.ts"));
40
- } else {
41
- options$.configFile = path.relative(cwd, path.resolve(dirname$1, "../shared.config.ts"));
42
- }
43
- await build$1(options$);
30
+ const build = async (format) => {
31
+ process.env.BUILD_OPTIONS = encodeURIComponent(JSON.stringify({
32
+ files,
33
+ format,
34
+ workspace,
35
+ packageName,
36
+ packageDir,
37
+ packageOptions
38
+ }));
39
+ let options$ = {
40
+ build: {
41
+ write: false
42
+ }
43
+ };
44
+ if (fs.existsSync(`${cwd}/z.build.config.ts`)) {
45
+ options$.configFile = path.relative(cwd, path.resolve(cwd, "./z.build.config.ts"));
46
+ } else if (fs.existsSync(`${cwd}/build.config.ts`)) {
47
+ options$.configFile = path.relative(cwd, path.resolve(cwd, "./build.config.ts"));
48
+ } else {
49
+ options$.configFile = path.relative(cwd, path.resolve(dirname$1, "../shared.config.ts"));
50
+ }
51
+ let viteBuild = await build$1(options$);
52
+ return viteBuild;
53
+ };
54
+ const formats = scriptFormats.split(",");
55
+ await formats.reduce(
56
+ (preProcess, format) => {
57
+ preProcess = preProcess.then(() => build(format)).then((outputs2) => {
58
+ outputs2.forEach((i) => {
59
+ i.output.forEach((j) => {
60
+ if (j.type === "asset") {
61
+ fs.outputFileSync(`${outDir}/${j.fileName}`, j.source);
62
+ return;
63
+ }
64
+ if (j.type === "chunk") {
65
+ fs.outputFileSync(`${outDir}/${j.name}.${format}.js`, j.code);
66
+ return;
67
+ }
68
+ });
69
+ });
70
+ });
71
+ return preProcess;
72
+ },
73
+ Promise.resolve()
74
+ );
44
75
  let outputs = fs.readdirSync(outDir).filter((i) => /^index(.*)(?!=\.d)\.js$/.test(i));
45
76
  outputs.forEach((file) => {
46
77
  let stat = fs.statSync(path.resolve(outDir, file));
@@ -56,7 +87,7 @@ const run$3 = async (options) => {
56
87
  const run$2 = async (options) => {
57
88
  const { packageDir } = options || {};
58
89
  const srcDir = path.resolve(packageDir, "./src");
59
- const styles = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index(.*)\.s?css$/.test(i)) : [];
90
+ const styles = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index\.(.*)\.?s?css$/.test(i)) : [];
60
91
  const stats = [];
61
92
  await styles.reduce(
62
93
  (preProcess, file) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deot/dev-builder",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "main": "dist/index.es.js",
5
5
  "module": "dist/index.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -34,7 +34,7 @@
34
34
  "postcss-flexbugs-fixes": "^5.0.2",
35
35
  "postcss-import": "^15.1.0",
36
36
  "postcss-url": "^10.1.3",
37
- "sass": "^1.62.1",
37
+ "sass": "~1.62.1",
38
38
  "vite": "^4.3.9"
39
39
  },
40
40
  "devDependencies": {
package/shared.config.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { createRequire } from "node:module";
1
2
  import * as path from 'node:path';
2
3
  import { defineConfig } from 'vite';
3
4
  import atImport from "postcss-import";
@@ -6,17 +7,51 @@ import flexBugs from "postcss-flexbugs-fixes";
6
7
  import cssnano from "cssnano";
7
8
  import autoprefixer from "autoprefixer";
8
9
 
10
+ const cwd = process.cwd();
11
+
9
12
  // options
10
13
  const buildOptions = JSON.parse(decodeURIComponent(process.env.BUILD_OPTIONS || '{}'));
11
14
 
12
- const { files = [], packageName, packageDir, packageOptions = {} } = buildOptions;
15
+ const {
16
+ format,
17
+ workspace,
18
+ files = [],
19
+ packageName,
20
+ packageDir,
21
+ packageOptions = {}
22
+ } = buildOptions;
23
+
24
+ const external = /(cjs|es)/.test(format)
25
+ ? [
26
+ /^node:/,
27
+ /^[a-zA-Z@]/,
28
+ ...Object
29
+ .keys({
30
+ ...packageOptions.dependencies,
31
+ ...packageOptions.peerDependencies
32
+ })
33
+ .map(i => new RegExp(`^${i}$`))
34
+ ]
35
+ : [];
36
+
37
+ // alias
38
+ const replacement = (name: string) => path.resolve(cwd, `./packages/${name}`);
39
+ const { name } = createRequire(cwd)(path.resolve(cwd, workspace ? `${workspace}/index` : '', 'package.json'));
40
+
41
+ const alias = workspace && !(/(cjs|es)/.test(format))
42
+ ? [
43
+ {
44
+ find: new RegExp(`^${name}$`),
45
+ replacement: replacement('index')
46
+ },
47
+ {
48
+
49
+ find: new RegExp(`^${name}-(.*?)$`),
50
+ replacement: replacement('$1')
51
+ }
52
+ ]
53
+ : [];
13
54
 
14
- const external = Object
15
- .keys({
16
- ...packageOptions.dependencies,
17
- ...packageOptions.peerDependencies
18
- })
19
- .map(i => new RegExp(`^${i}$`));
20
55
 
21
56
  export default defineConfig({
22
57
  plugins: [],
@@ -32,24 +67,15 @@ export default defineConfig({
32
67
  ]
33
68
  }
34
69
  },
70
+ resolve: { alias },
35
71
  build: {
36
72
  minify: false,
37
73
  target: 'esnext',
38
- outDir: path.resolve(packageDir, './dist'),
39
74
  lib: {
40
75
  entry: files.map((file: string) => path.resolve(packageDir, './src', file)),
41
- formats: ['es', 'cjs'], // iife需要控制单独控制external,目前还做不到
42
- name: packageName,
43
- fileName: (format, entryName) => {
44
- return `${entryName}.${format}.js`;
45
- }
76
+ formats: [format],
77
+ name: packageName.replace(/(_|-|^|.*\/)([^-_\/@])/g, (_match: any, _$1: any, $2: string) => $2.toUpperCase())
46
78
  },
47
- rollupOptions: {
48
- external: [
49
- /^node:/,
50
- /^[a-zA-Z@]/,
51
- ...external
52
- ]
53
- }
79
+ rollupOptions: { external }
54
80
  }
55
81
  });