@es-pkg/compile 1.0.11 → 1.0.13
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/cjs/index.d.ts +5 -3
- package/cjs/index.js +48 -51
- package/esm/index.d.ts +5 -3
- package/esm/index.js +48 -51
- package/package.json +2 -1
package/cjs/index.d.ts
CHANGED
package/cjs/index.js
CHANGED
|
@@ -9,6 +9,7 @@ var rollup = require('rollup');
|
|
|
9
9
|
var resolve = require('@rollup/plugin-node-resolve');
|
|
10
10
|
var commonjs = require('@rollup/plugin-commonjs');
|
|
11
11
|
var json = require('@rollup/plugin-json');
|
|
12
|
+
var dts = require('rollup-plugin-dts');
|
|
12
13
|
var postcss = require('rollup-plugin-postcss');
|
|
13
14
|
var autoprefixer = require('autoprefixer');
|
|
14
15
|
var cssnano = require('cssnano');
|
|
@@ -38,12 +39,12 @@ function _interopNamespace(e) {
|
|
|
38
39
|
return Object.freeze(n);
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
var gulp__default = /*#__PURE__*/_interopDefault(gulp);
|
|
42
42
|
var utils__namespace = /*#__PURE__*/_interopNamespace(utils);
|
|
43
43
|
var esConfig__namespace = /*#__PURE__*/_interopNamespace(esConfig);
|
|
44
44
|
var resolve__default = /*#__PURE__*/_interopDefault(resolve);
|
|
45
45
|
var commonjs__default = /*#__PURE__*/_interopDefault(commonjs);
|
|
46
46
|
var json__default = /*#__PURE__*/_interopDefault(json);
|
|
47
|
+
var dts__default = /*#__PURE__*/_interopDefault(dts);
|
|
47
48
|
var postcss__default = /*#__PURE__*/_interopDefault(postcss);
|
|
48
49
|
var autoprefixer__default = /*#__PURE__*/_interopDefault(autoprefixer);
|
|
49
50
|
var cssnano__default = /*#__PURE__*/_interopDefault(cssnano);
|
|
@@ -53,9 +54,9 @@ var esbuild__default = /*#__PURE__*/_interopDefault(esbuild);
|
|
|
53
54
|
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
54
55
|
|
|
55
56
|
const { remove, log, getValidPkgName, toPascalCase } = utils__namespace;
|
|
56
|
-
const { config,
|
|
57
|
+
const { config, shallowInputs, pkg, relativeToApp, resolveApp } = esConfig__namespace;
|
|
57
58
|
const name = getValidPkgName(pkg.name);
|
|
58
|
-
const clean = () => {
|
|
59
|
+
const clean = async () => {
|
|
59
60
|
log(`\u6E05\u9664 ${relativeToApp(config.es)} & ${relativeToApp(config.cjs)} \u76EE\u5F55---\u5F00\u59CB`);
|
|
60
61
|
const promises = [
|
|
61
62
|
remove(config.publishDir, true),
|
|
@@ -63,12 +64,15 @@ const clean = () => {
|
|
|
63
64
|
remove(config.cjs, true),
|
|
64
65
|
remove(config.iife, true)
|
|
65
66
|
];
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
});
|
|
67
|
+
await Promise.all(promises);
|
|
68
|
+
log(`\u6E05\u9664 ${relativeToApp(config.es)} & ${relativeToApp(config.cjs)} \u76EE\u5F55---\u7ED3\u675F`);
|
|
69
69
|
};
|
|
70
70
|
function getPostcss(extract) {
|
|
71
71
|
return postcss__default.default({
|
|
72
|
+
modules: {
|
|
73
|
+
localsConvention: "camelCase"
|
|
74
|
+
// ✅ 横线转驼峰命名
|
|
75
|
+
},
|
|
72
76
|
extensions: [".less", ".scss", ".sass"],
|
|
73
77
|
use: {
|
|
74
78
|
stylus: ["sass"],
|
|
@@ -87,29 +91,39 @@ function isNodeModule(id) {
|
|
|
87
91
|
return false;
|
|
88
92
|
}
|
|
89
93
|
}
|
|
90
|
-
function getInputOptions(
|
|
94
|
+
function getInputOptions(emit) {
|
|
95
|
+
var _a, _b, _c;
|
|
96
|
+
const defaultPlugins = [
|
|
97
|
+
json__default.default(),
|
|
98
|
+
resolve__default.default(),
|
|
99
|
+
commonjs__default.default({
|
|
100
|
+
defaultIsModuleExports: true,
|
|
101
|
+
esmExternals: true,
|
|
102
|
+
transformMixedEsModules: true
|
|
103
|
+
// 混合模块也转换
|
|
104
|
+
}),
|
|
105
|
+
emit ? dts__default.default({ compilerOptions: getCompilerOptions() }) : esbuild__default.default({ target: "es2018", format: "esm" }),
|
|
106
|
+
getPostcss(config.css.extract)
|
|
107
|
+
];
|
|
108
|
+
const plugins = ((_a = config.rollupOptions) == null ? void 0 : _a.plugins) ? (_c = (_b = config.rollupOptions) == null ? void 0 : _b.plugins) == null ? void 0 : _c.call(_b, defaultPlugins) : defaultPlugins;
|
|
91
109
|
return {
|
|
92
110
|
input: shallowInputs.filter((item) => !item.endsWith(".d.ts")),
|
|
93
111
|
external: (id) => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
112
|
+
var _a2;
|
|
113
|
+
const defaultExternal = (id2) => {
|
|
114
|
+
if (node_module.builtinModules.includes(id2)) return true;
|
|
115
|
+
return !!(!id2.startsWith(".") && !path__default.default.isAbsolute(id2) && isNodeModule(id2));
|
|
116
|
+
};
|
|
117
|
+
if ((_a2 = config.rollupOptions) == null ? void 0 : _a2.external) {
|
|
118
|
+
return config.rollupOptions.external(id, defaultExternal);
|
|
119
|
+
} else {
|
|
120
|
+
return defaultExternal(id);
|
|
121
|
+
}
|
|
97
122
|
},
|
|
98
|
-
plugins
|
|
99
|
-
json__default.default(),
|
|
100
|
-
resolve__default.default(),
|
|
101
|
-
commonjs__default.default({
|
|
102
|
-
defaultIsModuleExports: true,
|
|
103
|
-
esmExternals: true,
|
|
104
|
-
transformMixedEsModules: true
|
|
105
|
-
// 混合模块也转换
|
|
106
|
-
}),
|
|
107
|
-
esbuild__default.default({ target: "es2018", format: "esm" }),
|
|
108
|
-
getPostcss(config.css.extract)
|
|
109
|
-
]
|
|
123
|
+
plugins
|
|
110
124
|
};
|
|
111
125
|
}
|
|
112
|
-
|
|
126
|
+
function getCompilerOptions() {
|
|
113
127
|
const tsConfig = ts__default.default.readConfigFile(resolveApp("tsconfig.json"), ts__default.default.sys.readFile);
|
|
114
128
|
if (tsConfig.error) {
|
|
115
129
|
console.log(tsConfig.error.messageText);
|
|
@@ -119,7 +133,6 @@ async function buildDeclarations() {
|
|
|
119
133
|
ts__default.default.sys,
|
|
120
134
|
resolveApp("./")
|
|
121
135
|
);
|
|
122
|
-
const entryFiles = collectInputs.filter((item) => [".ts", ".tsx"].some((suf) => item.endsWith(suf)));
|
|
123
136
|
const compilerOptions = {
|
|
124
137
|
...parsedConfig.options,
|
|
125
138
|
declaration: true,
|
|
@@ -133,27 +146,7 @@ async function buildDeclarations() {
|
|
|
133
146
|
target: ts__default.default.ScriptTarget.ESNext,
|
|
134
147
|
module: ts__default.default.ModuleKind.ESNext
|
|
135
148
|
};
|
|
136
|
-
|
|
137
|
-
host.writeFile = (fileName, contents) => {
|
|
138
|
-
const dir = path__default.default.dirname(fileName);
|
|
139
|
-
fs__default.default.mkdirSync(dir, { recursive: true });
|
|
140
|
-
fs__default.default.writeFileSync(fileName, contents, "utf8");
|
|
141
|
-
};
|
|
142
|
-
const program = ts__default.default.createProgram(entryFiles, compilerOptions, host);
|
|
143
|
-
const emitResult = program.emit();
|
|
144
|
-
const diagnostics = ts__default.default.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
145
|
-
if (diagnostics.length > 0) {
|
|
146
|
-
console.error(
|
|
147
|
-
ts__default.default.formatDiagnosticsWithColorAndContext(diagnostics, {
|
|
148
|
-
getCanonicalFileName: (f) => f,
|
|
149
|
-
getCurrentDirectory: ts__default.default.sys.getCurrentDirectory,
|
|
150
|
-
getNewLine: () => ts__default.default.sys.newLine
|
|
151
|
-
})
|
|
152
|
-
);
|
|
153
|
-
} else {
|
|
154
|
-
console.log(`\u2705 Declarations generated in: ${path__default.default.resolve(config.es)}`);
|
|
155
|
-
}
|
|
156
|
-
log.success("\u2705 Declarations build complete!");
|
|
149
|
+
return compilerOptions;
|
|
157
150
|
}
|
|
158
151
|
async function buildExtraCss() {
|
|
159
152
|
const extras = config.css.extra;
|
|
@@ -192,7 +185,13 @@ async function buildExtraCss() {
|
|
|
192
185
|
await Promise.all(tasks);
|
|
193
186
|
log.success("\u2705 \u6240\u6709\u989D\u5916 CSS \u7F16\u8BD1\u5B8C\u6210");
|
|
194
187
|
}
|
|
188
|
+
async function buildDts() {
|
|
189
|
+
return build(true);
|
|
190
|
+
}
|
|
195
191
|
async function buildJS() {
|
|
192
|
+
return build(false);
|
|
193
|
+
}
|
|
194
|
+
async function build(emit) {
|
|
196
195
|
const outputOptions = [
|
|
197
196
|
{
|
|
198
197
|
dir: config.es,
|
|
@@ -218,14 +217,12 @@ async function buildJS() {
|
|
|
218
217
|
] : []
|
|
219
218
|
];
|
|
220
219
|
for (const output of outputOptions) {
|
|
221
|
-
const bundle = await rollup.rollup(getInputOptions(
|
|
220
|
+
const bundle = await rollup.rollup(getInputOptions(emit));
|
|
222
221
|
await bundle.write(output);
|
|
223
222
|
}
|
|
224
|
-
await buildExtraCss();
|
|
225
|
-
log.success(
|
|
223
|
+
!emit && await buildExtraCss();
|
|
224
|
+
log.success(`\u2705 ${emit ? "DTS " : "JS "}Build complete!`);
|
|
226
225
|
}
|
|
227
|
-
|
|
228
|
-
const copyTds = () => gulp__default.default.src([`${config.es}/**/*.d.ts`]).pipe(gulp__default.default.dest(config.cjs));
|
|
229
|
-
var src_default = gulp.series(clean, buildJS, buildDeclarations, copySrcTds, copyTds);
|
|
226
|
+
var src_default = gulp.series(clean, buildJS, buildDts);
|
|
230
227
|
|
|
231
228
|
exports.default = src_default;
|
package/esm/index.d.ts
CHANGED
package/esm/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { series } from '@es-pkg/gulp';
|
|
2
2
|
import * as utils from '@es-pkg/utils';
|
|
3
3
|
import * as esConfig from '@es-pkg/config';
|
|
4
4
|
import { rollup } from 'rollup';
|
|
5
5
|
import resolve from '@rollup/plugin-node-resolve';
|
|
6
6
|
import commonjs from '@rollup/plugin-commonjs';
|
|
7
7
|
import json from '@rollup/plugin-json';
|
|
8
|
+
import dts from 'rollup-plugin-dts';
|
|
8
9
|
import postcss from 'rollup-plugin-postcss';
|
|
9
10
|
import autoprefixer from 'autoprefixer';
|
|
10
11
|
import cssnano from 'cssnano';
|
|
@@ -15,9 +16,9 @@ import { builtinModules } from 'node:module';
|
|
|
15
16
|
import ts from 'typescript';
|
|
16
17
|
|
|
17
18
|
const { remove, log, getValidPkgName, toPascalCase } = utils;
|
|
18
|
-
const { config,
|
|
19
|
+
const { config, shallowInputs, pkg, relativeToApp, resolveApp } = esConfig;
|
|
19
20
|
const name = getValidPkgName(pkg.name);
|
|
20
|
-
const clean = () => {
|
|
21
|
+
const clean = async () => {
|
|
21
22
|
log(`\u6E05\u9664 ${relativeToApp(config.es)} & ${relativeToApp(config.cjs)} \u76EE\u5F55---\u5F00\u59CB`);
|
|
22
23
|
const promises = [
|
|
23
24
|
remove(config.publishDir, true),
|
|
@@ -25,12 +26,15 @@ const clean = () => {
|
|
|
25
26
|
remove(config.cjs, true),
|
|
26
27
|
remove(config.iife, true)
|
|
27
28
|
];
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
29
|
+
await Promise.all(promises);
|
|
30
|
+
log(`\u6E05\u9664 ${relativeToApp(config.es)} & ${relativeToApp(config.cjs)} \u76EE\u5F55---\u7ED3\u675F`);
|
|
31
31
|
};
|
|
32
32
|
function getPostcss(extract) {
|
|
33
33
|
return postcss({
|
|
34
|
+
modules: {
|
|
35
|
+
localsConvention: "camelCase"
|
|
36
|
+
// ✅ 横线转驼峰命名
|
|
37
|
+
},
|
|
34
38
|
extensions: [".less", ".scss", ".sass"],
|
|
35
39
|
use: {
|
|
36
40
|
stylus: ["sass"],
|
|
@@ -49,29 +53,39 @@ function isNodeModule(id) {
|
|
|
49
53
|
return false;
|
|
50
54
|
}
|
|
51
55
|
}
|
|
52
|
-
function getInputOptions(
|
|
56
|
+
function getInputOptions(emit) {
|
|
57
|
+
var _a, _b, _c;
|
|
58
|
+
const defaultPlugins = [
|
|
59
|
+
json(),
|
|
60
|
+
resolve(),
|
|
61
|
+
commonjs({
|
|
62
|
+
defaultIsModuleExports: true,
|
|
63
|
+
esmExternals: true,
|
|
64
|
+
transformMixedEsModules: true
|
|
65
|
+
// 混合模块也转换
|
|
66
|
+
}),
|
|
67
|
+
emit ? dts({ compilerOptions: getCompilerOptions() }) : esbuild({ target: "es2018", format: "esm" }),
|
|
68
|
+
getPostcss(config.css.extract)
|
|
69
|
+
];
|
|
70
|
+
const plugins = ((_a = config.rollupOptions) == null ? void 0 : _a.plugins) ? (_c = (_b = config.rollupOptions) == null ? void 0 : _b.plugins) == null ? void 0 : _c.call(_b, defaultPlugins) : defaultPlugins;
|
|
53
71
|
return {
|
|
54
72
|
input: shallowInputs.filter((item) => !item.endsWith(".d.ts")),
|
|
55
73
|
external: (id) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
74
|
+
var _a2;
|
|
75
|
+
const defaultExternal = (id2) => {
|
|
76
|
+
if (builtinModules.includes(id2)) return true;
|
|
77
|
+
return !!(!id2.startsWith(".") && !path.isAbsolute(id2) && isNodeModule(id2));
|
|
78
|
+
};
|
|
79
|
+
if ((_a2 = config.rollupOptions) == null ? void 0 : _a2.external) {
|
|
80
|
+
return config.rollupOptions.external(id, defaultExternal);
|
|
81
|
+
} else {
|
|
82
|
+
return defaultExternal(id);
|
|
83
|
+
}
|
|
59
84
|
},
|
|
60
|
-
plugins
|
|
61
|
-
json(),
|
|
62
|
-
resolve(),
|
|
63
|
-
commonjs({
|
|
64
|
-
defaultIsModuleExports: true,
|
|
65
|
-
esmExternals: true,
|
|
66
|
-
transformMixedEsModules: true
|
|
67
|
-
// 混合模块也转换
|
|
68
|
-
}),
|
|
69
|
-
esbuild({ target: "es2018", format: "esm" }),
|
|
70
|
-
getPostcss(config.css.extract)
|
|
71
|
-
]
|
|
85
|
+
plugins
|
|
72
86
|
};
|
|
73
87
|
}
|
|
74
|
-
|
|
88
|
+
function getCompilerOptions() {
|
|
75
89
|
const tsConfig = ts.readConfigFile(resolveApp("tsconfig.json"), ts.sys.readFile);
|
|
76
90
|
if (tsConfig.error) {
|
|
77
91
|
console.log(tsConfig.error.messageText);
|
|
@@ -81,7 +95,6 @@ async function buildDeclarations() {
|
|
|
81
95
|
ts.sys,
|
|
82
96
|
resolveApp("./")
|
|
83
97
|
);
|
|
84
|
-
const entryFiles = collectInputs.filter((item) => [".ts", ".tsx"].some((suf) => item.endsWith(suf)));
|
|
85
98
|
const compilerOptions = {
|
|
86
99
|
...parsedConfig.options,
|
|
87
100
|
declaration: true,
|
|
@@ -95,27 +108,7 @@ async function buildDeclarations() {
|
|
|
95
108
|
target: ts.ScriptTarget.ESNext,
|
|
96
109
|
module: ts.ModuleKind.ESNext
|
|
97
110
|
};
|
|
98
|
-
|
|
99
|
-
host.writeFile = (fileName, contents) => {
|
|
100
|
-
const dir = path.dirname(fileName);
|
|
101
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
102
|
-
fs.writeFileSync(fileName, contents, "utf8");
|
|
103
|
-
};
|
|
104
|
-
const program = ts.createProgram(entryFiles, compilerOptions, host);
|
|
105
|
-
const emitResult = program.emit();
|
|
106
|
-
const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
107
|
-
if (diagnostics.length > 0) {
|
|
108
|
-
console.error(
|
|
109
|
-
ts.formatDiagnosticsWithColorAndContext(diagnostics, {
|
|
110
|
-
getCanonicalFileName: (f) => f,
|
|
111
|
-
getCurrentDirectory: ts.sys.getCurrentDirectory,
|
|
112
|
-
getNewLine: () => ts.sys.newLine
|
|
113
|
-
})
|
|
114
|
-
);
|
|
115
|
-
} else {
|
|
116
|
-
console.log(`\u2705 Declarations generated in: ${path.resolve(config.es)}`);
|
|
117
|
-
}
|
|
118
|
-
log.success("\u2705 Declarations build complete!");
|
|
111
|
+
return compilerOptions;
|
|
119
112
|
}
|
|
120
113
|
async function buildExtraCss() {
|
|
121
114
|
const extras = config.css.extra;
|
|
@@ -154,7 +147,13 @@ async function buildExtraCss() {
|
|
|
154
147
|
await Promise.all(tasks);
|
|
155
148
|
log.success("\u2705 \u6240\u6709\u989D\u5916 CSS \u7F16\u8BD1\u5B8C\u6210");
|
|
156
149
|
}
|
|
150
|
+
async function buildDts() {
|
|
151
|
+
return build(true);
|
|
152
|
+
}
|
|
157
153
|
async function buildJS() {
|
|
154
|
+
return build(false);
|
|
155
|
+
}
|
|
156
|
+
async function build(emit) {
|
|
158
157
|
const outputOptions = [
|
|
159
158
|
{
|
|
160
159
|
dir: config.es,
|
|
@@ -180,14 +179,12 @@ async function buildJS() {
|
|
|
180
179
|
] : []
|
|
181
180
|
];
|
|
182
181
|
for (const output of outputOptions) {
|
|
183
|
-
const bundle = await rollup(getInputOptions(
|
|
182
|
+
const bundle = await rollup(getInputOptions(emit));
|
|
184
183
|
await bundle.write(output);
|
|
185
184
|
}
|
|
186
|
-
await buildExtraCss();
|
|
187
|
-
log.success(
|
|
185
|
+
!emit && await buildExtraCss();
|
|
186
|
+
log.success(`\u2705 ${emit ? "DTS " : "JS "}Build complete!`);
|
|
188
187
|
}
|
|
189
|
-
|
|
190
|
-
const copyTds = () => gulp.src([`${config.es}/**/*.d.ts`]).pipe(gulp.dest(config.cjs));
|
|
191
|
-
var src_default = series(clean, buildJS, buildDeclarations, copySrcTds, copyTds);
|
|
188
|
+
var src_default = series(clean, buildJS, buildDts);
|
|
192
189
|
|
|
193
190
|
export { src_default as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@es-pkg/compile",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "组件打包工具",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"rollup-plugin-esbuild": "latest",
|
|
29
29
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
30
30
|
"@rollup/plugin-json": "^6.1.0",
|
|
31
|
+
"rollup-plugin-dts": "^6.3.0",
|
|
31
32
|
"autoprefixer": "^10.4.21",
|
|
32
33
|
"cssnano": "latest",
|
|
33
34
|
"sass": "^1.53.0",
|