@es-pkg/publish 1.0.0 → 1.0.2

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.
Files changed (3) hide show
  1. package/cjs/index.js +68 -77
  2. package/esm/index.js +17 -13
  3. package/package.json +2 -2
package/cjs/index.js CHANGED
@@ -24,68 +24,55 @@ var scoped = /^@[a-zA-Z0-9-]+\/.+$/;
24
24
  var REGISTRY = "https://registry.npmjs.org";
25
25
  var json = _config.pkg;
26
26
  var publishDir = _path.default.join(_config.config.publishDir, './__npm__');
27
- _gulp.default.task('clean', /*#__PURE__*/function () {
28
- var _ref = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(cb) {
29
- return _regenerator.default.wrap(function _callee$(_context) {
30
- while (1) switch (_context.prev = _context.next) {
31
- case 0:
32
- (0, _utils.log)("\u6E05\u9664".concat(publishDir, "\u5F00\u59CB"));
33
- _context.prev = 1;
34
- _context.next = 4;
35
- return (0, _utils.remove)(publishDir);
36
- case 4:
37
- (0, _utils.log)("\u6E05\u9664".concat(publishDir, "\u5B8C\u6210"));
38
- _context.next = 10;
39
- break;
40
- case 7:
41
- _context.prev = 7;
42
- _context.t0 = _context["catch"](1);
43
- (0, _utils.log)("\u6E05\u9664".concat(publishDir, "\u5931\u8D25\uFF1A"), _context.t0);
44
- case 10:
45
- cb();
46
- case 11:
47
- case "end":
48
- return _context.stop();
49
- }
50
- }, _callee, null, [[1, 7]]);
51
- }));
52
- return function (_x) {
53
- return _ref.apply(this, arguments);
54
- };
55
- }());
56
- _gulp.default.task('del-cjs-iife-es', /*#__PURE__*/function () {
57
- var _ref2 = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2(cb) {
58
- return _regenerator.default.wrap(function _callee2$(_context2) {
59
- while (1) switch (_context2.prev = _context2.next) {
60
- case 0:
61
- (0, _utils.log)("\u5220\u9664 ".concat(_path.default.join("".concat(publishDir), _config.config.iife), " \u5F00\u59CB"));
62
- _context2.next = 3;
63
- return (0, _utils.remove)("".concat(_path.default.join("".concat(publishDir), _config.config.iife)));
64
- case 3:
65
- (0, _utils.log)("\u5220\u9664 ".concat(_path.default.join("".concat(publishDir), _config.config.iife), " \u7ED3\u675F"));
66
- (0, _utils.log)("\u5220\u9664 ".concat(_path.default.join("".concat(publishDir), _config.config.cjs), " \u5F00\u59CB"));
67
- _context2.next = 7;
68
- return (0, _utils.remove)("".concat(_path.default.join("".concat(publishDir), _config.config.cjs)));
69
- case 7:
70
- (0, _utils.log)("\u5220\u9664 ".concat(_path.default.join("".concat(publishDir), _config.config.cjs), " \u7ED3\u675F"));
71
- (0, _utils.log)("\u5220\u9664 ".concat(_path.default.join("".concat(publishDir), _config.config.es), " \u5F00\u59CB"));
72
- _context2.next = 11;
73
- return (0, _utils.remove)("".concat(_path.default.join("".concat(publishDir), _config.config.es)));
74
- case 11:
75
- (0, _utils.log)("\u5220\u9664 ".concat(_path.default.join("".concat(publishDir), _config.config.es), " \u7ED3\u675F"));
76
- cb();
77
- case 13:
78
- case "end":
79
- return _context2.stop();
80
- }
81
- }, _callee2);
82
- }));
83
- return function (_x2) {
84
- return _ref2.apply(this, arguments);
85
- };
86
- }());
87
- _gulp.default.task('copy-info', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee3() {
88
- var controller, _yield$import, fetch, errored, timer, response, res, _yield$prompts, version, es, cjs, iife, CJSExists, ESExists, IIFEExists, mainExists, browserExists, moduleExists, jsonStr, ex;
27
+ _gulp.default.task('clean', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee() {
28
+ return _regenerator.default.wrap(function _callee$(_context) {
29
+ while (1) switch (_context.prev = _context.next) {
30
+ case 0:
31
+ (0, _utils.log)("\u6E05\u9664".concat(publishDir, "\u5F00\u59CB"));
32
+ _context.prev = 1;
33
+ _context.next = 4;
34
+ return (0, _utils.remove)(publishDir);
35
+ case 4:
36
+ (0, _utils.log)("\u6E05\u9664".concat(publishDir, "\u5B8C\u6210"));
37
+ _context.next = 10;
38
+ break;
39
+ case 7:
40
+ _context.prev = 7;
41
+ _context.t0 = _context["catch"](1);
42
+ (0, _utils.log)("\u6E05\u9664".concat(publishDir, "\u5931\u8D25\uFF1A"), _context.t0);
43
+ case 10:
44
+ case "end":
45
+ return _context.stop();
46
+ }
47
+ }, _callee, null, [[1, 7]]);
48
+ })));
49
+ _gulp.default.task('del-cjs-iife-es', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2() {
50
+ return _regenerator.default.wrap(function _callee2$(_context2) {
51
+ while (1) switch (_context2.prev = _context2.next) {
52
+ case 0:
53
+ (0, _utils.log)("\u5220\u9664 ".concat(_path.default.join("".concat(publishDir), _config.config.iife), " \u5F00\u59CB"));
54
+ _context2.next = 3;
55
+ return (0, _utils.remove)("".concat(_path.default.join("".concat(publishDir), _config.config.iife)));
56
+ case 3:
57
+ (0, _utils.log)("\u5220\u9664 ".concat(_path.default.join("".concat(publishDir), _config.config.iife), " \u7ED3\u675F"));
58
+ (0, _utils.log)("\u5220\u9664 ".concat(_path.default.join("".concat(publishDir), _config.config.cjs), " \u5F00\u59CB"));
59
+ _context2.next = 7;
60
+ return (0, _utils.remove)("".concat(_path.default.join("".concat(publishDir), _config.config.cjs)));
61
+ case 7:
62
+ (0, _utils.log)("\u5220\u9664 ".concat(_path.default.join("".concat(publishDir), _config.config.cjs), " \u7ED3\u675F"));
63
+ (0, _utils.log)("\u5220\u9664 ".concat(_path.default.join("".concat(publishDir), _config.config.es), " \u5F00\u59CB"));
64
+ _context2.next = 11;
65
+ return (0, _utils.remove)("".concat(_path.default.join("".concat(publishDir), _config.config.es)));
66
+ case 11:
67
+ (0, _utils.log)("\u5220\u9664 ".concat(_path.default.join("".concat(publishDir), _config.config.es), " \u7ED3\u675F"));
68
+ case 12:
69
+ case "end":
70
+ return _context2.stop();
71
+ }
72
+ }, _callee2);
73
+ })));
74
+ _gulp.default.task('copy-info', (0, _gulp.series)(/*#__PURE__*/(0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee3() {
75
+ var controller, _yield$import, fetch, errored, timer, response, res, _yield$prompts, version, es, cjs, iife, CJSExists, ESExists, IIFEExists, mainExists, browserExists, moduleExists, _es, _cjs, jsonStr, ex;
89
76
  return _regenerator.default.wrap(function _callee3$(_context3) {
90
77
  while (1) switch (_context3.prev = _context3.next) {
91
78
  case 0:
@@ -165,22 +152,24 @@ _gulp.default.task('copy-info', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#
165
152
  mainExists = !!json.main && _fs.default.existsSync(_path.default.join((0, _config.resolveApp)(''), json.main));
166
153
  browserExists = !!json.browser && _fs.default.existsSync(_path.default.join((0, _config.resolveApp)(''), json.main));
167
154
  moduleExists = !!json.module && _fs.default.existsSync(_path.default.join((0, _config.resolveApp)(''), json.main));
155
+ _es = (0, _config.getEntrypoint)(_config.config.es);
156
+ _cjs = (0, _config.getEntrypoint)(_config.config.cjs);
168
157
  if (!mainExists) {
169
158
  if (ESExists) {
170
- json.main = (0, _config.getEntrypoint)(_config.config.es);
159
+ json.main = _es || _cjs;
171
160
  }
172
161
  if (CJSExists) {
173
- json.main = (0, _config.getEntrypoint)(_config.config.cjs);
162
+ json.main = _cjs || _es;
174
163
  }
175
164
  }
176
165
  if (!moduleExists && CJSExists) {
177
- json.module = (0, _config.getEntrypoint)(_config.config.es);
166
+ json.module = (0, _config.getEntrypoint)(_config.config.es) || _es || _cjs;
178
167
  }
179
168
  if (!browserExists && IIFEExists) {
180
169
  json.browser = (0, _config.getEntrypoint)(_config.config.iife);
181
170
  }
182
171
  if (!json.types) {
183
- json.types = _path.default.basename(_config.config.typings);
172
+ json.types = (0, _config.getEntrypoint)(_config.config.es, _config.config.typings) || _es || _cjs;
184
173
  }
185
174
  json.files = [ESExists && es, CJSExists && cjs, IIFEExists && iife].filter(Boolean);
186
175
  json.dependencies = Object.fromEntries(Object.entries(json.dependencies).map(function (_ref4) {
@@ -205,19 +194,18 @@ _gulp.default.task('copy-info', /*#__PURE__*/(0, _asyncToGenerator2.default)(/*#
205
194
  _fs.default.writeFileSync("".concat(publishDir, "/.npmrc"), "registry=".concat(REGISTRY));
206
195
  (0, _utils.log)("\u751F\u6210 .npmrc \u5B8C\u6210");
207
196
  (0, _utils.log)("\u62F7\u8D1D README \u5F00\u59CB");
208
- return _context3.abrupt("return", _gulp.default.src(["./README.md"], {
209
- allowEmpty: true
210
- }).pipe((0, _gulpLogger.default)({
211
- before: 'copy README...',
212
- after: 'copy README complete!',
213
- showChange: false
214
- })).pipe(_gulp.default.dest("".concat(publishDir, "/"))));
215
- case 56:
197
+ case 57:
216
198
  case "end":
217
199
  return _context3.stop();
218
200
  }
219
201
  }, _callee3, null, [[7, 19]]);
220
- })));
202
+ })), function () {
203
+ return _gulp.default.src(["./README.md"]).pipe((0, _gulpLogger.default)({
204
+ before: 'copy README...',
205
+ after: 'copy README complete!',
206
+ showChange: false
207
+ })).pipe(_gulp.default.dest("".concat(publishDir, "/")));
208
+ }));
221
209
  _gulp.default.task('copy-iife', function () {
222
210
  (0, _utils.log)("\u62F7\u8D1D '/iife/**' \u5F00\u59CB");
223
211
  return _gulp.default.src(["".concat(_config.config.iife, "/.**"), "".concat(_config.config.iife, "/**")]).pipe((0, _gulpLogger.default)({
@@ -241,10 +229,13 @@ _gulp.default.task('copy-es', function () {
241
229
  })).pipe(_gulp.default.dest(_path.default.join("".concat(publishDir), _path.default.basename(_config.config.es))));
242
230
  });
243
231
  _gulp.default.task('remove-__npm__', (0, _gulp.series)(function () {
244
- var promises = [(0, _utils.remove)(_config.config.es), (0, _utils.remove)(_config.config.cjs), (0, _utils.remove)(_config.config.iife)];
232
+ var promises = [];
233
+ if (_config.config.removeCompiled) {
234
+ promises = [(0, _utils.remove)(_config.config.es), (0, _utils.remove)(_config.config.cjs), (0, _utils.remove)(_config.config.iife)];
235
+ }
245
236
  return Promise.all(promises);
246
237
  }, function () {
247
- return _gulp.default.src(["".concat(publishDir, "/.**"), "".concat(publishDir, "/**")]).pipe((0, _gulpLogger.default)({
238
+ return _gulp.default.src(["".concat(publishDir, "/**"), "".concat(publishDir, "/.**")]).pipe((0, _gulpLogger.default)({
248
239
  before: 'copy __npm__...',
249
240
  after: 'copy __npm__ complete!',
250
241
  showChange: false
package/esm/index.js CHANGED
@@ -10,7 +10,7 @@ const scoped = /^@[a-zA-Z0-9-]+\/.+$/;
10
10
  const REGISTRY = "https://registry.npmjs.org";
11
11
  const json = pkg;
12
12
  const publishDir = path.join(config.publishDir, './__npm__');
13
- gulp.task('clean', async (cb) => {
13
+ gulp.task('clean', async () => {
14
14
  log(`清除${publishDir}开始`);
15
15
  try {
16
16
  await remove(publishDir);
@@ -19,9 +19,8 @@ gulp.task('clean', async (cb) => {
19
19
  catch (e) {
20
20
  log(`清除${publishDir}失败:`, e);
21
21
  }
22
- cb();
23
22
  });
24
- gulp.task('del-cjs-iife-es', async (cb) => {
23
+ gulp.task('del-cjs-iife-es', async () => {
25
24
  log(`删除 ${path.join(`${publishDir}`, config.iife)} 开始`);
26
25
  await remove(`${path.join(`${publishDir}`, config.iife)}`);
27
26
  log(`删除 ${path.join(`${publishDir}`, config.iife)} 结束`);
@@ -31,9 +30,8 @@ gulp.task('del-cjs-iife-es', async (cb) => {
31
30
  log(`删除 ${path.join(`${publishDir}`, config.es)} 开始`);
32
31
  await remove(`${path.join(`${publishDir}`, config.es)}`);
33
32
  log(`删除 ${path.join(`${publishDir}`, config.es)} 结束`);
34
- cb();
35
33
  });
36
- gulp.task('copy-info', async () => {
34
+ gulp.task('copy-info', series(async () => {
37
35
  log(`生成 package 开始`);
38
36
  const controller = new AbortController();
39
37
  const { default: fetch } = await import("node-fetch");
@@ -90,22 +88,24 @@ gulp.task('copy-info', async () => {
90
88
  const mainExists = !!json.main && fs.existsSync(path.join(resolveApp(''), json.main));
91
89
  const browserExists = !!json.browser && fs.existsSync(path.join(resolveApp(''), json.main));
92
90
  const moduleExists = !!json.module && fs.existsSync(path.join(resolveApp(''), json.main));
91
+ const _es = getEntrypoint(config.es);
92
+ const _cjs = getEntrypoint(config.cjs);
93
93
  if (!mainExists) {
94
94
  if (ESExists) {
95
- json.main = getEntrypoint(config.es);
95
+ json.main = _es || _cjs;
96
96
  }
97
97
  if (CJSExists) {
98
- json.main = getEntrypoint(config.cjs);
98
+ json.main = _cjs || _es;
99
99
  }
100
100
  }
101
101
  if (!moduleExists && CJSExists) {
102
- json.module = getEntrypoint(config.es);
102
+ json.module = getEntrypoint(config.es) || _es || _cjs;
103
103
  }
104
104
  if (!browserExists && IIFEExists) {
105
105
  json.browser = getEntrypoint(config.iife);
106
106
  }
107
107
  if (!json.types) {
108
- json.types = path.basename(config.typings);
108
+ json.types = getEntrypoint(config.es, config.typings) || _es || _cjs;
109
109
  }
110
110
  json.files = [ESExists && es, CJSExists && cjs, IIFEExists && iife].filter(Boolean);
111
111
  json.dependencies = Object.fromEntries(Object.entries(json.dependencies).map(([key, value]) => {
@@ -125,14 +125,15 @@ gulp.task('copy-info', async () => {
125
125
  fs.writeFileSync(`${publishDir}/.npmrc`, `registry=${REGISTRY}`);
126
126
  log(`生成 .npmrc 完成`);
127
127
  log(`拷贝 README 开始`);
128
- return gulp.src([`./README.md`], { allowEmpty: true })
128
+ }, () => {
129
+ return gulp.src([`./README.md`])
129
130
  .pipe(logger({
130
131
  before: 'copy README...',
131
132
  after: 'copy README complete!',
132
133
  showChange: false
133
134
  }))
134
135
  .pipe(gulp.dest(`${publishDir}/`));
135
- });
136
+ }));
136
137
  gulp.task('copy-iife', () => {
137
138
  log(`拷贝 '/iife/**' 开始`);
138
139
  return gulp.src([`${config.iife}/.**`, `${config.iife}/**`])
@@ -162,10 +163,13 @@ gulp.task('copy-es', () => {
162
163
  .pipe(gulp.dest(path.join(`${publishDir}`, path.basename(config.es))));
163
164
  });
164
165
  gulp.task('remove-__npm__', series(() => {
165
- const promises = [remove(config.es), remove(config.cjs), remove(config.iife)];
166
+ let promises = [];
167
+ if (config.removeCompiled) {
168
+ promises = [remove(config.es), remove(config.cjs), remove(config.iife)];
169
+ }
166
170
  return Promise.all(promises);
167
171
  }, () => {
168
- return gulp.src([`${publishDir}/.**`, `${publishDir}/**`])
172
+ return gulp.src([`${publishDir}/**`, `${publishDir}/.**`])
169
173
  .pipe(logger({
170
174
  before: 'copy __npm__...',
171
175
  after: 'copy __npm__ complete!',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@es-pkg/publish",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "组件打包工具",
5
5
  "main": "cjs/index.js",
6
6
  "engines": {
@@ -30,7 +30,7 @@
30
30
  "registry": "https://registry.npmjs.org"
31
31
  },
32
32
  "module": "esm/index.js",
33
- "types": "typings",
33
+ "types": "esm/index.js",
34
34
  "files": [
35
35
  "esm",
36
36
  "cjs"