@es-pkg/publish 1.0.11 → 1.0.12
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 +54 -25
- package/esm/index.d.ts +5 -3
- package/esm/index.js +55 -26
- package/package.json +1 -1
- package/cjs/type.d.ts +0 -46
- package/esm/type.d.ts +0 -46
package/cjs/index.d.ts
CHANGED
package/cjs/index.js
CHANGED
|
@@ -39,9 +39,11 @@ gulp__default.default.task("del-cjs-iife-es", async () => {
|
|
|
39
39
|
await utils.remove(`${path__default.default.join(`${publishDir}`, config.config.iife)}`);
|
|
40
40
|
utils.log(`\u5220\u9664 ${path__default.default.join(`${publishDir}`, config.config.iife)} \u7ED3\u675F`);
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
if (config.config.cjs) {
|
|
43
|
+
utils.log(`\u5220\u9664 ${path__default.default.join(`${publishDir}`, config.config.cjs)} \u5F00\u59CB`);
|
|
44
|
+
await utils.remove(`${path__default.default.join(`${publishDir}`, config.config.cjs)}`);
|
|
45
|
+
utils.log(`\u5220\u9664 ${path__default.default.join(`${publishDir}`, config.config.cjs)} \u7ED3\u675F`);
|
|
46
|
+
}
|
|
45
47
|
utils.log(`\u5220\u9664 ${path__default.default.join(`${publishDir}`, config.config.es)} \u5F00\u59CB`);
|
|
46
48
|
await utils.remove(`${path__default.default.join(`${publishDir}`, config.config.es)}`);
|
|
47
49
|
utils.log(`\u5220\u9664 ${path__default.default.join(`${publishDir}`, config.config.es)} \u7ED3\u675F`);
|
|
@@ -104,31 +106,56 @@ gulp__default.default.task("copy-info", gulp.series(async () => {
|
|
|
104
106
|
}
|
|
105
107
|
const publishDir2 = config.resolveApp(config.config.publishDir);
|
|
106
108
|
const es = path__default.default.basename(config.config.es);
|
|
107
|
-
const cjs = path__default.default.basename(config.config.cjs);
|
|
109
|
+
const cjs = config.config.cjs ? path__default.default.basename(config.config.cjs) : "";
|
|
108
110
|
const iife = config.config.iife ? path__default.default.basename(config.config.iife) : "";
|
|
109
111
|
const has = {
|
|
110
112
|
es: fs__default.default.existsSync(path__default.default.join(publishDir2, es)),
|
|
111
|
-
cjs: fs__default.default.existsSync(path__default.default.join(publishDir2, cjs)),
|
|
113
|
+
cjs: config.config.cjs && fs__default.default.existsSync(path__default.default.join(publishDir2, cjs)),
|
|
112
114
|
iife: iife && fs__default.default.existsSync(path__default.default.join(publishDir2, iife))
|
|
113
115
|
};
|
|
114
116
|
const entry = (base, sub = config.config.entry) => config.getPublishedEntry(base, sub);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (has.es) {
|
|
119
|
-
json.module = entry(config.config.es);
|
|
120
|
-
}
|
|
121
|
-
if (has.iife) {
|
|
122
|
-
json.browser = entry(config.config.iife, "es");
|
|
123
|
-
}
|
|
124
|
-
if (!json.types) {
|
|
125
|
-
const typeEntry = has.es ? entry(config.config.es) : has.cjs ? entry(config.config.cjs) : "";
|
|
126
|
-
if (typeEntry) {
|
|
127
|
-
const { dir, name, ext } = path__default.default.parse(typeEntry);
|
|
128
|
-
json.types = [".ts", ".tsx"].includes(ext) ? typeEntry : `${dir}/${name}.d.ts`;
|
|
117
|
+
const fillField = (field, call) => {
|
|
118
|
+
if (!json[field]) {
|
|
119
|
+
return call();
|
|
129
120
|
}
|
|
130
|
-
|
|
131
|
-
|
|
121
|
+
const fields = Array.isArray(json[field]) ? json[field] : [json[field]];
|
|
122
|
+
const matched = fields.every((item) => {
|
|
123
|
+
const p = path__default.default.join(publishDir2, item.replaceAll(".ts", ".js"));
|
|
124
|
+
return fs__default.default.existsSync(config.resolveApp(item)) && fs__default.default.existsSync(config.resolveApp(p));
|
|
125
|
+
});
|
|
126
|
+
if (matched) {
|
|
127
|
+
json[field] = Array.isArray(json[field]) ? json[field].map((item) => item.replaceAll(".ts", ".js")) : json[field].replaceAll(".ts", field === "typings" ? ".d.ts" : ".js");
|
|
128
|
+
} else {
|
|
129
|
+
call();
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
fillField("main", () => {
|
|
133
|
+
if (has.es || has.cjs) {
|
|
134
|
+
json.main = (config.config.cjs ? entry(config.config.cjs) : "") || entry(config.config.es);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
fillField("module", () => {
|
|
138
|
+
if (has.es) {
|
|
139
|
+
json.module = entry(config.config.es);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
fillField("browser", () => {
|
|
143
|
+
if (has.iife) {
|
|
144
|
+
json.browser = entry(config.config.iife, "es");
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
fillField("types", () => {
|
|
148
|
+
if (!json.types) {
|
|
149
|
+
const typeEntry = has.es ? entry(config.config.es) : has.cjs ? config.config.cjs ? entry(config.config.cjs) : "" : "";
|
|
150
|
+
if (typeEntry) {
|
|
151
|
+
const { dir, name, ext } = path__default.default.parse(typeEntry);
|
|
152
|
+
json.types = [".ts", ".tsx"].includes(ext) ? typeEntry : `${dir}/${name}.d.ts`;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
fillField("files", () => {
|
|
157
|
+
json.files = Array.from(/* @__PURE__ */ new Set([has.es && es, has.cjs && cjs, has.iife && iife])).filter(Boolean);
|
|
158
|
+
});
|
|
132
159
|
if (json.dependencies) {
|
|
133
160
|
json.dependencies = Object.fromEntries(Object.entries(json.dependencies).map(([key, value]) => {
|
|
134
161
|
if (value.startsWith("file://") || value.startsWith("workspace:")) {
|
|
@@ -166,7 +193,10 @@ gulp__default.default.task("copy-iife", (c) => {
|
|
|
166
193
|
showChange: false
|
|
167
194
|
})).pipe(gulp__default.default.dest(path__default.default.join(`${publishDir}`, path__default.default.basename(config.config.iife))));
|
|
168
195
|
});
|
|
169
|
-
gulp__default.default.task("copy-cjs", () => {
|
|
196
|
+
gulp__default.default.task("copy-cjs", (c) => {
|
|
197
|
+
if (!config.config.cjs) {
|
|
198
|
+
return c();
|
|
199
|
+
}
|
|
170
200
|
return gulp__default.default.src([`${config.config.cjs}/.**`, `${config.config.cjs}/**`]).pipe(logger__default.default({
|
|
171
201
|
before: "copy cjs...",
|
|
172
202
|
after: "copy cjs complete!",
|
|
@@ -182,12 +212,11 @@ gulp__default.default.task("copy-es", () => {
|
|
|
182
212
|
});
|
|
183
213
|
gulp__default.default.task("remove-__npm__", gulp.series(() => {
|
|
184
214
|
let promises = [];
|
|
185
|
-
const includes = [config.config.es, config.config.cjs, config.config.iife].flatMap((val) => {
|
|
215
|
+
const includes = [config.config.es, config.config.cjs, config.config.iife].filter(Boolean).flatMap((val) => {
|
|
186
216
|
if (!val) {
|
|
187
217
|
return [];
|
|
188
218
|
}
|
|
189
|
-
|
|
190
|
-
return some ? [] : [val];
|
|
219
|
+
return [path__default.default.join(`${publishDir}`, path__default.default.basename(val))];
|
|
191
220
|
});
|
|
192
221
|
promises = includes.map((item) => utils.remove(item));
|
|
193
222
|
return Promise.all(promises);
|
package/esm/index.d.ts
CHANGED
package/esm/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import logger from '@es-pkg/gulp-logger';
|
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import { log, remove, run, fetch, autoUpgrade, compare, success, error } from '@es-pkg/utils';
|
|
7
|
-
import { config, pkg, resolveApp, getPublishedEntry
|
|
7
|
+
import { config, pkg, resolveApp, getPublishedEntry } from '@es-pkg/config';
|
|
8
8
|
import prompts from 'prompts';
|
|
9
9
|
|
|
10
10
|
const scoped = /^@[a-zA-Z0-9-]+\/.+$/;
|
|
@@ -26,9 +26,11 @@ gulp.task("del-cjs-iife-es", async () => {
|
|
|
26
26
|
await remove(`${path.join(`${publishDir}`, config.iife)}`);
|
|
27
27
|
log(`\u5220\u9664 ${path.join(`${publishDir}`, config.iife)} \u7ED3\u675F`);
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
if (config.cjs) {
|
|
30
|
+
log(`\u5220\u9664 ${path.join(`${publishDir}`, config.cjs)} \u5F00\u59CB`);
|
|
31
|
+
await remove(`${path.join(`${publishDir}`, config.cjs)}`);
|
|
32
|
+
log(`\u5220\u9664 ${path.join(`${publishDir}`, config.cjs)} \u7ED3\u675F`);
|
|
33
|
+
}
|
|
32
34
|
log(`\u5220\u9664 ${path.join(`${publishDir}`, config.es)} \u5F00\u59CB`);
|
|
33
35
|
await remove(`${path.join(`${publishDir}`, config.es)}`);
|
|
34
36
|
log(`\u5220\u9664 ${path.join(`${publishDir}`, config.es)} \u7ED3\u675F`);
|
|
@@ -91,31 +93,56 @@ gulp.task("copy-info", series(async () => {
|
|
|
91
93
|
}
|
|
92
94
|
const publishDir2 = resolveApp(config.publishDir);
|
|
93
95
|
const es = path.basename(config.es);
|
|
94
|
-
const cjs = path.basename(config.cjs);
|
|
96
|
+
const cjs = config.cjs ? path.basename(config.cjs) : "";
|
|
95
97
|
const iife = config.iife ? path.basename(config.iife) : "";
|
|
96
98
|
const has = {
|
|
97
99
|
es: fs.existsSync(path.join(publishDir2, es)),
|
|
98
|
-
cjs: fs.existsSync(path.join(publishDir2, cjs)),
|
|
100
|
+
cjs: config.cjs && fs.existsSync(path.join(publishDir2, cjs)),
|
|
99
101
|
iife: iife && fs.existsSync(path.join(publishDir2, iife))
|
|
100
102
|
};
|
|
101
103
|
const entry = (base, sub = config.entry) => getPublishedEntry(base, sub);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (has.es) {
|
|
106
|
-
json.module = entry(config.es);
|
|
107
|
-
}
|
|
108
|
-
if (has.iife) {
|
|
109
|
-
json.browser = entry(config.iife, "es");
|
|
110
|
-
}
|
|
111
|
-
if (!json.types) {
|
|
112
|
-
const typeEntry = has.es ? entry(config.es) : has.cjs ? entry(config.cjs) : "";
|
|
113
|
-
if (typeEntry) {
|
|
114
|
-
const { dir, name, ext } = path.parse(typeEntry);
|
|
115
|
-
json.types = [".ts", ".tsx"].includes(ext) ? typeEntry : `${dir}/${name}.d.ts`;
|
|
104
|
+
const fillField = (field, call) => {
|
|
105
|
+
if (!json[field]) {
|
|
106
|
+
return call();
|
|
116
107
|
}
|
|
117
|
-
|
|
118
|
-
|
|
108
|
+
const fields = Array.isArray(json[field]) ? json[field] : [json[field]];
|
|
109
|
+
const matched = fields.every((item) => {
|
|
110
|
+
const p = path.join(publishDir2, item.replaceAll(".ts", ".js"));
|
|
111
|
+
return fs.existsSync(resolveApp(item)) && fs.existsSync(resolveApp(p));
|
|
112
|
+
});
|
|
113
|
+
if (matched) {
|
|
114
|
+
json[field] = Array.isArray(json[field]) ? json[field].map((item) => item.replaceAll(".ts", ".js")) : json[field].replaceAll(".ts", field === "typings" ? ".d.ts" : ".js");
|
|
115
|
+
} else {
|
|
116
|
+
call();
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
fillField("main", () => {
|
|
120
|
+
if (has.es || has.cjs) {
|
|
121
|
+
json.main = (config.cjs ? entry(config.cjs) : "") || entry(config.es);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
fillField("module", () => {
|
|
125
|
+
if (has.es) {
|
|
126
|
+
json.module = entry(config.es);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
fillField("browser", () => {
|
|
130
|
+
if (has.iife) {
|
|
131
|
+
json.browser = entry(config.iife, "es");
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
fillField("types", () => {
|
|
135
|
+
if (!json.types) {
|
|
136
|
+
const typeEntry = has.es ? entry(config.es) : has.cjs ? config.cjs ? entry(config.cjs) : "" : "";
|
|
137
|
+
if (typeEntry) {
|
|
138
|
+
const { dir, name, ext } = path.parse(typeEntry);
|
|
139
|
+
json.types = [".ts", ".tsx"].includes(ext) ? typeEntry : `${dir}/${name}.d.ts`;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
fillField("files", () => {
|
|
144
|
+
json.files = Array.from(/* @__PURE__ */ new Set([has.es && es, has.cjs && cjs, has.iife && iife])).filter(Boolean);
|
|
145
|
+
});
|
|
119
146
|
if (json.dependencies) {
|
|
120
147
|
json.dependencies = Object.fromEntries(Object.entries(json.dependencies).map(([key, value]) => {
|
|
121
148
|
if (value.startsWith("file://") || value.startsWith("workspace:")) {
|
|
@@ -153,7 +180,10 @@ gulp.task("copy-iife", (c) => {
|
|
|
153
180
|
showChange: false
|
|
154
181
|
})).pipe(gulp.dest(path.join(`${publishDir}`, path.basename(config.iife))));
|
|
155
182
|
});
|
|
156
|
-
gulp.task("copy-cjs", () => {
|
|
183
|
+
gulp.task("copy-cjs", (c) => {
|
|
184
|
+
if (!config.cjs) {
|
|
185
|
+
return c();
|
|
186
|
+
}
|
|
157
187
|
return gulp.src([`${config.cjs}/.**`, `${config.cjs}/**`]).pipe(logger({
|
|
158
188
|
before: "copy cjs...",
|
|
159
189
|
after: "copy cjs complete!",
|
|
@@ -169,12 +199,11 @@ gulp.task("copy-es", () => {
|
|
|
169
199
|
});
|
|
170
200
|
gulp.task("remove-__npm__", series(() => {
|
|
171
201
|
let promises = [];
|
|
172
|
-
const includes = [config.es, config.cjs, config.iife].flatMap((val) => {
|
|
202
|
+
const includes = [config.es, config.cjs, config.iife].filter(Boolean).flatMap((val) => {
|
|
173
203
|
if (!val) {
|
|
174
204
|
return [];
|
|
175
205
|
}
|
|
176
|
-
|
|
177
|
-
return some ? [] : [val];
|
|
206
|
+
return [path.join(`${publishDir}`, path.basename(val))];
|
|
178
207
|
});
|
|
179
208
|
promises = includes.map((item) => remove(item));
|
|
180
209
|
return Promise.all(promises);
|
package/package.json
CHANGED
package/cjs/type.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
declare module "rename" {
|
|
4
|
-
export = rename;
|
|
5
|
-
|
|
6
|
-
function rename(filepath: string | rename.FileObject, transformer: rename.Transformer): rename.FilePath;
|
|
7
|
-
|
|
8
|
-
namespace rename {
|
|
9
|
-
interface FileObject {
|
|
10
|
-
// using package's terminology
|
|
11
|
-
dirname?: string | undefined;
|
|
12
|
-
basename?: string | undefined;
|
|
13
|
-
extname?: string | undefined;
|
|
14
|
-
path?: string | undefined;
|
|
15
|
-
hash?: string | undefined; // not populated by package
|
|
16
|
-
origin?: string | undefined;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface Specification {
|
|
20
|
-
dirname?: string | undefined;
|
|
21
|
-
prefix?: string | undefined;
|
|
22
|
-
basename?: string | undefined;
|
|
23
|
-
suffix?: string | undefined;
|
|
24
|
-
extname?: string | undefined;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
type FilePath =
|
|
28
|
-
| string
|
|
29
|
-
| Specification;
|
|
30
|
-
|
|
31
|
-
type Transformer =
|
|
32
|
-
| ((spec: FileObject) => FilePath)
|
|
33
|
-
| FilePath;
|
|
34
|
-
|
|
35
|
-
interface ParsedFileObject {
|
|
36
|
-
dirname: string;
|
|
37
|
-
extname: string;
|
|
38
|
-
basename: string;
|
|
39
|
-
origin: string;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function parse(filename: string | Partial<ParsedFileObject>): ParsedFileObject;
|
|
43
|
-
|
|
44
|
-
function stringify(obj: FileObject): string;
|
|
45
|
-
}
|
|
46
|
-
}
|
package/esm/type.d.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
declare module "rename" {
|
|
4
|
-
export = rename;
|
|
5
|
-
|
|
6
|
-
function rename(filepath: string | rename.FileObject, transformer: rename.Transformer): rename.FilePath;
|
|
7
|
-
|
|
8
|
-
namespace rename {
|
|
9
|
-
interface FileObject {
|
|
10
|
-
// using package's terminology
|
|
11
|
-
dirname?: string | undefined;
|
|
12
|
-
basename?: string | undefined;
|
|
13
|
-
extname?: string | undefined;
|
|
14
|
-
path?: string | undefined;
|
|
15
|
-
hash?: string | undefined; // not populated by package
|
|
16
|
-
origin?: string | undefined;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
interface Specification {
|
|
20
|
-
dirname?: string | undefined;
|
|
21
|
-
prefix?: string | undefined;
|
|
22
|
-
basename?: string | undefined;
|
|
23
|
-
suffix?: string | undefined;
|
|
24
|
-
extname?: string | undefined;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
type FilePath =
|
|
28
|
-
| string
|
|
29
|
-
| Specification;
|
|
30
|
-
|
|
31
|
-
type Transformer =
|
|
32
|
-
| ((spec: FileObject) => FilePath)
|
|
33
|
-
| FilePath;
|
|
34
|
-
|
|
35
|
-
interface ParsedFileObject {
|
|
36
|
-
dirname: string;
|
|
37
|
-
extname: string;
|
|
38
|
-
basename: string;
|
|
39
|
-
origin: string;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function parse(filename: string | Partial<ParsedFileObject>): ParsedFileObject;
|
|
43
|
-
|
|
44
|
-
function stringify(obj: FileObject): string;
|
|
45
|
-
}
|
|
46
|
-
}
|