@es-pkg/compile 1.0.12 → 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 +41 -47
- package/esm/index.d.ts +5 -3
- package/esm/index.js +41 -47
- 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,7 +54,7 @@ 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
59
|
const clean = async () => {
|
|
59
60
|
log(`\u6E05\u9664 ${relativeToApp(config.es)} & ${relativeToApp(config.cjs)} \u76EE\u5F55---\u5F00\u59CB`);
|
|
@@ -90,29 +91,39 @@ function isNodeModule(id) {
|
|
|
90
91
|
return false;
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
|
-
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;
|
|
94
109
|
return {
|
|
95
110
|
input: shallowInputs.filter((item) => !item.endsWith(".d.ts")),
|
|
96
111
|
external: (id) => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
+
}
|
|
100
122
|
},
|
|
101
|
-
plugins
|
|
102
|
-
json__default.default(),
|
|
103
|
-
resolve__default.default(),
|
|
104
|
-
commonjs__default.default({
|
|
105
|
-
defaultIsModuleExports: true,
|
|
106
|
-
esmExternals: true,
|
|
107
|
-
transformMixedEsModules: true
|
|
108
|
-
// 混合模块也转换
|
|
109
|
-
}),
|
|
110
|
-
esbuild__default.default({ target: "es2018", format: "esm" }),
|
|
111
|
-
getPostcss(config.css.extract)
|
|
112
|
-
]
|
|
123
|
+
plugins
|
|
113
124
|
};
|
|
114
125
|
}
|
|
115
|
-
|
|
126
|
+
function getCompilerOptions() {
|
|
116
127
|
const tsConfig = ts__default.default.readConfigFile(resolveApp("tsconfig.json"), ts__default.default.sys.readFile);
|
|
117
128
|
if (tsConfig.error) {
|
|
118
129
|
console.log(tsConfig.error.messageText);
|
|
@@ -122,7 +133,6 @@ async function buildDeclarations() {
|
|
|
122
133
|
ts__default.default.sys,
|
|
123
134
|
resolveApp("./")
|
|
124
135
|
);
|
|
125
|
-
const entryFiles = collectInputs.filter((item) => [".ts", ".tsx"].some((suf) => item.endsWith(suf)));
|
|
126
136
|
const compilerOptions = {
|
|
127
137
|
...parsedConfig.options,
|
|
128
138
|
declaration: true,
|
|
@@ -136,27 +146,7 @@ async function buildDeclarations() {
|
|
|
136
146
|
target: ts__default.default.ScriptTarget.ESNext,
|
|
137
147
|
module: ts__default.default.ModuleKind.ESNext
|
|
138
148
|
};
|
|
139
|
-
|
|
140
|
-
host.writeFile = (fileName, contents) => {
|
|
141
|
-
const dir = path__default.default.dirname(fileName);
|
|
142
|
-
fs__default.default.mkdirSync(dir, { recursive: true });
|
|
143
|
-
fs__default.default.writeFileSync(fileName, contents, "utf8");
|
|
144
|
-
};
|
|
145
|
-
const program = ts__default.default.createProgram(entryFiles, compilerOptions, host);
|
|
146
|
-
const emitResult = program.emit();
|
|
147
|
-
const diagnostics = ts__default.default.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
148
|
-
if (diagnostics.length > 0) {
|
|
149
|
-
console.error(
|
|
150
|
-
ts__default.default.formatDiagnosticsWithColorAndContext(diagnostics, {
|
|
151
|
-
getCanonicalFileName: (f) => f,
|
|
152
|
-
getCurrentDirectory: ts__default.default.sys.getCurrentDirectory,
|
|
153
|
-
getNewLine: () => ts__default.default.sys.newLine
|
|
154
|
-
})
|
|
155
|
-
);
|
|
156
|
-
} else {
|
|
157
|
-
console.log(`\u2705 Declarations generated in: ${path__default.default.resolve(config.es)}`);
|
|
158
|
-
}
|
|
159
|
-
log.success("\u2705 Declarations build complete!");
|
|
149
|
+
return compilerOptions;
|
|
160
150
|
}
|
|
161
151
|
async function buildExtraCss() {
|
|
162
152
|
const extras = config.css.extra;
|
|
@@ -195,7 +185,13 @@ async function buildExtraCss() {
|
|
|
195
185
|
await Promise.all(tasks);
|
|
196
186
|
log.success("\u2705 \u6240\u6709\u989D\u5916 CSS \u7F16\u8BD1\u5B8C\u6210");
|
|
197
187
|
}
|
|
188
|
+
async function buildDts() {
|
|
189
|
+
return build(true);
|
|
190
|
+
}
|
|
198
191
|
async function buildJS() {
|
|
192
|
+
return build(false);
|
|
193
|
+
}
|
|
194
|
+
async function build(emit) {
|
|
199
195
|
const outputOptions = [
|
|
200
196
|
{
|
|
201
197
|
dir: config.es,
|
|
@@ -221,14 +217,12 @@ async function buildJS() {
|
|
|
221
217
|
] : []
|
|
222
218
|
];
|
|
223
219
|
for (const output of outputOptions) {
|
|
224
|
-
const bundle = await rollup.rollup(getInputOptions(
|
|
220
|
+
const bundle = await rollup.rollup(getInputOptions(emit));
|
|
225
221
|
await bundle.write(output);
|
|
226
222
|
}
|
|
227
|
-
await buildExtraCss();
|
|
228
|
-
log.success(
|
|
223
|
+
!emit && await buildExtraCss();
|
|
224
|
+
log.success(`\u2705 ${emit ? "DTS " : "JS "}Build complete!`);
|
|
229
225
|
}
|
|
230
|
-
|
|
231
|
-
const copyTds = () => gulp__default.default.src([`${config.es}/**/*.d.ts`]).pipe(gulp__default.default.dest(config.cjs));
|
|
232
|
-
var src_default = gulp.series(clean, buildJS, buildDeclarations, copySrcTds, copyTds);
|
|
226
|
+
var src_default = gulp.series(clean, buildJS, buildDts);
|
|
233
227
|
|
|
234
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,7 +16,7 @@ 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
21
|
const clean = async () => {
|
|
21
22
|
log(`\u6E05\u9664 ${relativeToApp(config.es)} & ${relativeToApp(config.cjs)} \u76EE\u5F55---\u5F00\u59CB`);
|
|
@@ -52,29 +53,39 @@ function isNodeModule(id) {
|
|
|
52
53
|
return false;
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
|
-
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;
|
|
56
71
|
return {
|
|
57
72
|
input: shallowInputs.filter((item) => !item.endsWith(".d.ts")),
|
|
58
73
|
external: (id) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
}
|
|
62
84
|
},
|
|
63
|
-
plugins
|
|
64
|
-
json(),
|
|
65
|
-
resolve(),
|
|
66
|
-
commonjs({
|
|
67
|
-
defaultIsModuleExports: true,
|
|
68
|
-
esmExternals: true,
|
|
69
|
-
transformMixedEsModules: true
|
|
70
|
-
// 混合模块也转换
|
|
71
|
-
}),
|
|
72
|
-
esbuild({ target: "es2018", format: "esm" }),
|
|
73
|
-
getPostcss(config.css.extract)
|
|
74
|
-
]
|
|
85
|
+
plugins
|
|
75
86
|
};
|
|
76
87
|
}
|
|
77
|
-
|
|
88
|
+
function getCompilerOptions() {
|
|
78
89
|
const tsConfig = ts.readConfigFile(resolveApp("tsconfig.json"), ts.sys.readFile);
|
|
79
90
|
if (tsConfig.error) {
|
|
80
91
|
console.log(tsConfig.error.messageText);
|
|
@@ -84,7 +95,6 @@ async function buildDeclarations() {
|
|
|
84
95
|
ts.sys,
|
|
85
96
|
resolveApp("./")
|
|
86
97
|
);
|
|
87
|
-
const entryFiles = collectInputs.filter((item) => [".ts", ".tsx"].some((suf) => item.endsWith(suf)));
|
|
88
98
|
const compilerOptions = {
|
|
89
99
|
...parsedConfig.options,
|
|
90
100
|
declaration: true,
|
|
@@ -98,27 +108,7 @@ async function buildDeclarations() {
|
|
|
98
108
|
target: ts.ScriptTarget.ESNext,
|
|
99
109
|
module: ts.ModuleKind.ESNext
|
|
100
110
|
};
|
|
101
|
-
|
|
102
|
-
host.writeFile = (fileName, contents) => {
|
|
103
|
-
const dir = path.dirname(fileName);
|
|
104
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
105
|
-
fs.writeFileSync(fileName, contents, "utf8");
|
|
106
|
-
};
|
|
107
|
-
const program = ts.createProgram(entryFiles, compilerOptions, host);
|
|
108
|
-
const emitResult = program.emit();
|
|
109
|
-
const diagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
110
|
-
if (diagnostics.length > 0) {
|
|
111
|
-
console.error(
|
|
112
|
-
ts.formatDiagnosticsWithColorAndContext(diagnostics, {
|
|
113
|
-
getCanonicalFileName: (f) => f,
|
|
114
|
-
getCurrentDirectory: ts.sys.getCurrentDirectory,
|
|
115
|
-
getNewLine: () => ts.sys.newLine
|
|
116
|
-
})
|
|
117
|
-
);
|
|
118
|
-
} else {
|
|
119
|
-
console.log(`\u2705 Declarations generated in: ${path.resolve(config.es)}`);
|
|
120
|
-
}
|
|
121
|
-
log.success("\u2705 Declarations build complete!");
|
|
111
|
+
return compilerOptions;
|
|
122
112
|
}
|
|
123
113
|
async function buildExtraCss() {
|
|
124
114
|
const extras = config.css.extra;
|
|
@@ -157,7 +147,13 @@ async function buildExtraCss() {
|
|
|
157
147
|
await Promise.all(tasks);
|
|
158
148
|
log.success("\u2705 \u6240\u6709\u989D\u5916 CSS \u7F16\u8BD1\u5B8C\u6210");
|
|
159
149
|
}
|
|
150
|
+
async function buildDts() {
|
|
151
|
+
return build(true);
|
|
152
|
+
}
|
|
160
153
|
async function buildJS() {
|
|
154
|
+
return build(false);
|
|
155
|
+
}
|
|
156
|
+
async function build(emit) {
|
|
161
157
|
const outputOptions = [
|
|
162
158
|
{
|
|
163
159
|
dir: config.es,
|
|
@@ -183,14 +179,12 @@ async function buildJS() {
|
|
|
183
179
|
] : []
|
|
184
180
|
];
|
|
185
181
|
for (const output of outputOptions) {
|
|
186
|
-
const bundle = await rollup(getInputOptions(
|
|
182
|
+
const bundle = await rollup(getInputOptions(emit));
|
|
187
183
|
await bundle.write(output);
|
|
188
184
|
}
|
|
189
|
-
await buildExtraCss();
|
|
190
|
-
log.success(
|
|
185
|
+
!emit && await buildExtraCss();
|
|
186
|
+
log.success(`\u2705 ${emit ? "DTS " : "JS "}Build complete!`);
|
|
191
187
|
}
|
|
192
|
-
|
|
193
|
-
const copyTds = () => gulp.src([`${config.es}/**/*.d.ts`]).pipe(gulp.dest(config.cjs));
|
|
194
|
-
var src_default = series(clean, buildJS, buildDeclarations, copySrcTds, copyTds);
|
|
188
|
+
var src_default = series(clean, buildJS, buildDts);
|
|
195
189
|
|
|
196
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",
|