@deot/dev-builder 2.5.3 → 2.6.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 +33 -30
- package/dist/{index.es.js → index.js} +30 -28
- package/package.json +11 -11
- package/shared.config.ts +33 -6
package/dist/index.cjs
CHANGED
|
@@ -22,6 +22,7 @@ const cssnano = require('cssnano');
|
|
|
22
22
|
const autoprefixer = require('autoprefixer');
|
|
23
23
|
const apiExtractor = require('@microsoft/api-extractor');
|
|
24
24
|
|
|
25
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
25
26
|
function _interopNamespaceDefault(e) {
|
|
26
27
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
|
|
27
28
|
if (e) {
|
|
@@ -43,7 +44,7 @@ const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
|
43
44
|
const fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs$1);
|
|
44
45
|
const sass__namespace = /*#__PURE__*/_interopNamespaceDefault(sass);
|
|
45
46
|
|
|
46
|
-
const dirname$1 = path__namespace.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (
|
|
47
|
+
const dirname$1 = path__namespace.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
|
|
47
48
|
const run$3 = async (options) => {
|
|
48
49
|
const locals = devShared.Locals.impl();
|
|
49
50
|
const { cwd, workspace } = locals;
|
|
@@ -58,15 +59,17 @@ const run$3 = async (options) => {
|
|
|
58
59
|
isVuePackage,
|
|
59
60
|
isReactPackage
|
|
60
61
|
} = options || {};
|
|
61
|
-
const { scriptFormats } = commandOptions;
|
|
62
|
+
const { scriptFormats, external, globals } = commandOptions;
|
|
62
63
|
const stats = [];
|
|
63
64
|
let files = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index\.(.*)\.?(t|j)s$/.test(i)) : [];
|
|
64
65
|
if (!files.length)
|
|
65
66
|
return stats;
|
|
66
|
-
const build = async (format) => {
|
|
67
|
+
const build = async (format, filepath) => {
|
|
67
68
|
const buildOptions = {
|
|
68
|
-
files,
|
|
69
|
+
files: [filepath],
|
|
69
70
|
format,
|
|
71
|
+
external,
|
|
72
|
+
globals,
|
|
70
73
|
workspace,
|
|
71
74
|
packageName,
|
|
72
75
|
packageDir,
|
|
@@ -94,38 +97,38 @@ const run$3 = async (options) => {
|
|
|
94
97
|
options$ = isVuePackage ? vite.mergeConfig(sharedVueConfig, options$) : isReactPackage ? vite.mergeConfig(sharedReactConfig, options$) : options$;
|
|
95
98
|
}
|
|
96
99
|
process.env.BUILD_OPTIONS = encodeURIComponent(JSON.stringify(buildOptions));
|
|
97
|
-
let
|
|
98
|
-
|
|
100
|
+
let outputs2 = await vite.build(options$);
|
|
101
|
+
outputs2.forEach((i) => {
|
|
102
|
+
i.output.forEach((j) => {
|
|
103
|
+
if (j.type === "asset") {
|
|
104
|
+
let fileName = filepath.replace(/^(.*)((\..*\.js)|\.cjs|\.ts)/, `$1.${j.fileName}`);
|
|
105
|
+
fs.outputFileSync(`${outDir}/${fileName}`, j.source);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (j.type === "chunk") {
|
|
109
|
+
fs.outputFileSync(`${outDir}/${j.fileName}`, j.code);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
return outputs2;
|
|
99
115
|
};
|
|
100
116
|
const formats = scriptFormats.split(",").filter((i) => {
|
|
101
117
|
return !isNodePackage || ["es", "cjs"].includes(i);
|
|
102
118
|
});
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
112
|
-
if (j.type === "chunk") {
|
|
113
|
-
fs.outputFileSync(`${outDir}/${j.name}.${format}${format === "cjs" ? "" : ".js"}`, j.code);
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
return preProcess;
|
|
120
|
-
},
|
|
121
|
-
Promise.resolve()
|
|
122
|
-
);
|
|
123
|
-
let outputs = fs.readdirSync(outDir).filter((i) => /^index(.*)(?!=\.d)\.c?js$/.test(i));
|
|
119
|
+
let serial = Promise.resolve();
|
|
120
|
+
formats.forEach((format) => {
|
|
121
|
+
files.forEach((filepath) => {
|
|
122
|
+
serial = serial.then(() => build(format, filepath));
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
await serial;
|
|
126
|
+
let outputs = fs.readdirSync(outDir).filter((i) => /^index(.*)(?!=(\.d))\.(cjs|js|style\.css)$/.test(i));
|
|
124
127
|
outputs.forEach((file) => {
|
|
125
128
|
let stat = fs.statSync(path__namespace.resolve(outDir, file));
|
|
126
129
|
stats.push({
|
|
127
|
-
file: file.replace(/^(.*)((\..*\.js)|\.cjs)/, "$1.ts"),
|
|
128
|
-
format: file
|
|
130
|
+
file: file.replace(/^(.*)((\..*\.js)|\.umd\.cjs)/, "$1.ts").replace(/^(.*)(\.js|\.cjs)/, "$1.ts"),
|
|
131
|
+
format: /\.style\.css$/.test(file) ? "css" : /\.umd\.cjs$/.test(file) ? "umd" : /\.cjs$/.test(file) ? "cjs" : /\.iife\.cjs$/.test(file) ? "iife" : "es",
|
|
129
132
|
size: stat.size
|
|
130
133
|
});
|
|
131
134
|
});
|
|
@@ -159,7 +162,7 @@ const run$2 = async (options) => {
|
|
|
159
162
|
return stats;
|
|
160
163
|
};
|
|
161
164
|
|
|
162
|
-
const dirname = path__namespace.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (
|
|
165
|
+
const dirname = path__namespace.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
|
|
163
166
|
const run$1 = async (options) => {
|
|
164
167
|
const { workspace, packageDir: packageRootDir } = devShared.Locals.impl();
|
|
165
168
|
const { isVuePackage, packageDir, packageOutDir, packageSourceDir, packageOptions, commandOptions } = options;
|
|
@@ -33,15 +33,17 @@ const run$3 = async (options) => {
|
|
|
33
33
|
isVuePackage,
|
|
34
34
|
isReactPackage
|
|
35
35
|
} = options || {};
|
|
36
|
-
const { scriptFormats } = commandOptions;
|
|
36
|
+
const { scriptFormats, external, globals } = commandOptions;
|
|
37
37
|
const stats = [];
|
|
38
38
|
let files = fs$1.existsSync(srcDir) ? fs$1.readdirSync(srcDir).filter((i) => /^index\.(.*)\.?(t|j)s$/.test(i)) : [];
|
|
39
39
|
if (!files.length)
|
|
40
40
|
return stats;
|
|
41
|
-
const build = async (format) => {
|
|
41
|
+
const build = async (format, filepath) => {
|
|
42
42
|
const buildOptions = {
|
|
43
|
-
files,
|
|
43
|
+
files: [filepath],
|
|
44
44
|
format,
|
|
45
|
+
external,
|
|
46
|
+
globals,
|
|
45
47
|
workspace,
|
|
46
48
|
packageName,
|
|
47
49
|
packageDir,
|
|
@@ -69,38 +71,38 @@ const run$3 = async (options) => {
|
|
|
69
71
|
options$ = isVuePackage ? mergeConfig(sharedVueConfig, options$) : isReactPackage ? mergeConfig(sharedReactConfig, options$) : options$;
|
|
70
72
|
}
|
|
71
73
|
process.env.BUILD_OPTIONS = encodeURIComponent(JSON.stringify(buildOptions));
|
|
72
|
-
let
|
|
73
|
-
|
|
74
|
+
let outputs2 = await build$1(options$);
|
|
75
|
+
outputs2.forEach((i) => {
|
|
76
|
+
i.output.forEach((j) => {
|
|
77
|
+
if (j.type === "asset") {
|
|
78
|
+
let fileName = filepath.replace(/^(.*)((\..*\.js)|\.cjs|\.ts)/, `$1.${j.fileName}`);
|
|
79
|
+
fs$1.outputFileSync(`${outDir}/${fileName}`, j.source);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (j.type === "chunk") {
|
|
83
|
+
fs$1.outputFileSync(`${outDir}/${j.fileName}`, j.code);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
return outputs2;
|
|
74
89
|
};
|
|
75
90
|
const formats = scriptFormats.split(",").filter((i) => {
|
|
76
91
|
return !isNodePackage || ["es", "cjs"].includes(i);
|
|
77
92
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
if (j.type === "chunk") {
|
|
88
|
-
fs$1.outputFileSync(`${outDir}/${j.name}.${format}${format === "cjs" ? "" : ".js"}`, j.code);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
return preProcess;
|
|
95
|
-
},
|
|
96
|
-
Promise.resolve()
|
|
97
|
-
);
|
|
98
|
-
let outputs = fs$1.readdirSync(outDir).filter((i) => /^index(.*)(?!=\.d)\.c?js$/.test(i));
|
|
93
|
+
let serial = Promise.resolve();
|
|
94
|
+
formats.forEach((format) => {
|
|
95
|
+
files.forEach((filepath) => {
|
|
96
|
+
serial = serial.then(() => build(format, filepath));
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
await serial;
|
|
100
|
+
let outputs = fs$1.readdirSync(outDir).filter((i) => /^index(.*)(?!=(\.d))\.(cjs|js|style\.css)$/.test(i));
|
|
99
101
|
outputs.forEach((file) => {
|
|
100
102
|
let stat = fs$1.statSync(path.resolve(outDir, file));
|
|
101
103
|
stats.push({
|
|
102
|
-
file: file.replace(/^(.*)((\..*\.js)|\.cjs)/, "$1.ts"),
|
|
103
|
-
format: file
|
|
104
|
+
file: file.replace(/^(.*)((\..*\.js)|\.umd\.cjs)/, "$1.ts").replace(/^(.*)(\.js|\.cjs)/, "$1.ts"),
|
|
105
|
+
format: /\.style\.css$/.test(file) ? "css" : /\.umd\.cjs$/.test(file) ? "umd" : /\.cjs$/.test(file) ? "cjs" : /\.iife\.cjs$/.test(file) ? "iife" : "es",
|
|
104
106
|
size: stat.size
|
|
105
107
|
});
|
|
106
108
|
});
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deot/dev-builder",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "dist/index.
|
|
5
|
+
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
-
"import": "./dist/index.
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
10
|
"require": "./dist/index.cjs",
|
|
11
11
|
"types": "./dist/index.d.ts"
|
|
12
12
|
}
|
|
@@ -29,21 +29,21 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@deot/dev-react": "^2.
|
|
33
|
-
"@deot/dev-shared": "^2.
|
|
34
|
-
"@deot/dev-vue": "^2.
|
|
35
|
-
"@microsoft/api-extractor": "^7.
|
|
36
|
-
"autoprefixer": "^10.4.
|
|
32
|
+
"@deot/dev-react": "^2.6.0",
|
|
33
|
+
"@deot/dev-shared": "^2.6.0",
|
|
34
|
+
"@deot/dev-vue": "^2.6.0",
|
|
35
|
+
"@microsoft/api-extractor": "^7.38.1",
|
|
36
|
+
"autoprefixer": "^10.4.16",
|
|
37
37
|
"chalk": "^5.3.0",
|
|
38
38
|
"cssnano": "^6.0.1",
|
|
39
39
|
"fs-extra": "^11.1.1",
|
|
40
40
|
"ora": "^7.0.1",
|
|
41
|
-
"postcss": "^8.4.
|
|
41
|
+
"postcss": "^8.4.31",
|
|
42
42
|
"postcss-flexbugs-fixes": "^5.0.2",
|
|
43
43
|
"postcss-import": "^15.1.0",
|
|
44
44
|
"postcss-url": "^10.1.3",
|
|
45
|
-
"sass": "^1.
|
|
46
|
-
"vite": "^4.
|
|
45
|
+
"sass": "^1.69.5",
|
|
46
|
+
"vite": "^4.5.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"typescript": "^5.1.6"
|
package/shared.config.ts
CHANGED
|
@@ -15,6 +15,8 @@ const buildOptions = JSON.parse(decodeURIComponent(process.env.BUILD_OPTIONS ||
|
|
|
15
15
|
|
|
16
16
|
const {
|
|
17
17
|
format,
|
|
18
|
+
external = '',
|
|
19
|
+
globals = '',
|
|
18
20
|
workspace,
|
|
19
21
|
files = [],
|
|
20
22
|
packageName,
|
|
@@ -22,7 +24,8 @@ const {
|
|
|
22
24
|
packageOptions = {}
|
|
23
25
|
} = buildOptions;
|
|
24
26
|
|
|
25
|
-
const
|
|
27
|
+
const usedForBrowser = /(iife|umd)/.test(format);
|
|
28
|
+
const external$ = !usedForBrowser
|
|
26
29
|
? [
|
|
27
30
|
/^node:/,
|
|
28
31
|
/^[a-zA-Z@]/,
|
|
@@ -33,13 +36,15 @@ const external = /(cjs|es)/.test(format)
|
|
|
33
36
|
})
|
|
34
37
|
.map(i => new RegExp(`^${i}$`))
|
|
35
38
|
]
|
|
36
|
-
:
|
|
39
|
+
: external.split(',')
|
|
40
|
+
.filter((i: string) => !!i)
|
|
41
|
+
.map((i: string) => new RegExp(`^${i}$`));
|
|
37
42
|
|
|
38
43
|
// alias
|
|
39
44
|
const replacement = (name: string) => path.resolve(cwd, `./packages/${name}`);
|
|
40
45
|
const { name } = createRequire(cwd)(path.resolve(cwd, workspace ? `${workspace}/index` : '', 'package.json'));
|
|
41
46
|
|
|
42
|
-
const alias = workspace &&
|
|
47
|
+
const alias = workspace && usedForBrowser
|
|
43
48
|
? [
|
|
44
49
|
{
|
|
45
50
|
find: new RegExp(`^${name}$`),
|
|
@@ -53,10 +58,16 @@ const alias = workspace && !(/(cjs|es)/.test(format))
|
|
|
53
58
|
]
|
|
54
59
|
: [];
|
|
55
60
|
|
|
61
|
+
const getGlobalName = (name$: string) => name$.replace(/(_|-|^|.*\/)([^-_\/@])/g, (_match: any, _$1: any, $2: string) => $2.toUpperCase());
|
|
56
62
|
|
|
57
63
|
export default defineConfig({
|
|
58
|
-
|
|
64
|
+
define: usedForBrowser
|
|
65
|
+
? {
|
|
66
|
+
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV)
|
|
67
|
+
}
|
|
68
|
+
: {},
|
|
59
69
|
logLevel: 'silent',
|
|
70
|
+
plugins: [],
|
|
60
71
|
css: {
|
|
61
72
|
postcss: {
|
|
62
73
|
plugins: [
|
|
@@ -75,8 +86,24 @@ export default defineConfig({
|
|
|
75
86
|
lib: {
|
|
76
87
|
entry: files.map((file: string) => path.resolve(packageSourceDir, file)),
|
|
77
88
|
formats: [format],
|
|
78
|
-
name: packageName
|
|
89
|
+
name: getGlobalName(packageName)
|
|
79
90
|
},
|
|
80
|
-
rollupOptions: {
|
|
91
|
+
rollupOptions: {
|
|
92
|
+
external: external$,
|
|
93
|
+
output: {
|
|
94
|
+
globals: usedForBrowser
|
|
95
|
+
? (globals || external).split(',')
|
|
96
|
+
.filter((i: string) => !!i)
|
|
97
|
+
.reduce((pre: any, cur: string) => {
|
|
98
|
+
const [key, value] = cur.split(':');
|
|
99
|
+
if (key) {
|
|
100
|
+
pre[key] = value || getGlobalName(key);
|
|
101
|
+
}
|
|
102
|
+
return pre;
|
|
103
|
+
}, {})
|
|
104
|
+
: {}
|
|
105
|
+
|
|
106
|
+
}
|
|
107
|
+
}
|
|
81
108
|
}
|
|
82
109
|
}) as UserConfig;
|