js-build-tools 5.3.0 → 5.3.1
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/README.md +26 -0
- package/dist/build.js +63 -63
- package/dist/partials/imagesFor.js +42 -48
- package/dist/partials/loadPeer.js +99 -0
- package/dist/partials/standardLint.js +73 -75
- package/dist/partials/tsFor.js +70 -82
- package/dist/partials/typeDocsFor.js +35 -21
- package/dist/partials.js +19 -0
- package/dist/partials.min.js +1 -1
- package/dist/typeDocs.js +9 -9
- package/functions/partials/imagesFor.mjs +7 -13
- package/functions/partials/loadPeer.mjs +75 -0
- package/functions/partials/loadPeer.test.mjs +58 -0
- package/functions/partials/standardLint.mjs +3 -5
- package/functions/partials/tsFor.mjs +4 -20
- package/functions/partials/typeDocsFor.mjs +27 -22
- package/functions/partials/typeDocsFor.test.mjs +26 -5
- package/functions/partials.mjs +1 -0
- package/functions/partials.test.mjs +1 -1
- package/gulp.config.mjs +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,6 +35,11 @@ provided are the defaults):
|
|
|
35
35
|
"name": "my-package",
|
|
36
36
|
// The search pattern used for retrieving compiled distribution files.
|
|
37
37
|
"from": "dist/**/*.js",
|
|
38
|
+
// Module names or file paths which resolve to an empty object ({}) in the bundle instead of their real contents.
|
|
39
|
+
"ignore": [],
|
|
40
|
+
// Module names or file paths left out of the bundle entirely (requiring one at runtime throws, unless something
|
|
41
|
+
// else provides it, for example a script tag which loads it separately).
|
|
42
|
+
"exclude": [],
|
|
38
43
|
// The output directory for browser-bundled files.
|
|
39
44
|
"to": "browser"
|
|
40
45
|
},
|
|
@@ -290,6 +295,27 @@ const jsDocBase = require('js-build-tools/jsdoc.base')
|
|
|
290
295
|
module.exports = jsDocBase
|
|
291
296
|
```
|
|
292
297
|
|
|
298
|
+
### Configure what the browser bundle leaves out (optional)
|
|
299
|
+
|
|
300
|
+
A dependency can be reached from your code without being needed in the browser, and bundling it can add a lot of size.
|
|
301
|
+
Two settings in `browser` handle this, both take module names or file paths (see browserify's `b.ignore(file)` and
|
|
302
|
+
`b.exclude(file)`):
|
|
303
|
+
|
|
304
|
+
```json
|
|
305
|
+
{
|
|
306
|
+
"browser": {
|
|
307
|
+
// Resolves to an empty object ({}) in the bundle instead of the real module. This suits a dependency which is only
|
|
308
|
+
// reached because it is the default value of an option you always override with your own (for example a selector
|
|
309
|
+
// engine's default DOM adapter). Anything only that module requires is left out too. Your code must never actually
|
|
310
|
+
// use the real module, so keep overriding that option.
|
|
311
|
+
"ignore": ["some-default-adapter"],
|
|
312
|
+
// Left out of the bundle entirely. Requiring it at runtime throws unless something else provides it, for example a
|
|
313
|
+
// script tag which loads it separately, so this suits a large library which the page already loads.
|
|
314
|
+
"exclude": ["a-library-the-page-loads"]
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
293
319
|
### Configure move fonts (optional)
|
|
294
320
|
|
|
295
321
|
Be able to copy a source directory of fonts into the distribution path.
|
package/dist/build.js
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
require('core-js/modules/esnext.weak-map.delete-all.js')
|
|
4
|
-
Object.defineProperty(exports, '__esModule', {
|
|
5
|
-
value: true
|
|
6
|
-
})
|
|
7
|
-
exports.build = void 0
|
|
8
|
-
const _bundle = require('./bundle.js')
|
|
9
|
-
const _bundleLint = require('./bundleLint.js')
|
|
10
|
-
const _bundleMinify = require('./bundleMinify.js')
|
|
11
|
-
const _partials = require('./partials.js')
|
|
12
|
-
const _compileReadme = require('./compileReadme.js')
|
|
13
|
-
const _typeDocs = require('./typeDocs.js')
|
|
14
|
-
const _distLint = require('./distLint.js')
|
|
15
|
-
const _distMinify = require('./distMinify.js')
|
|
16
|
-
const _gulp = require('gulp')
|
|
17
|
-
const gulpConfig = _interopRequireWildcard(require('../gulp.config.js'))
|
|
18
|
-
const _copyFonts = require('./copyFonts.js')
|
|
19
|
-
const _images = require('./images.js')
|
|
20
|
-
const _sass = require('./sass.js')
|
|
21
|
-
const _testFull = require('./testFull.js')
|
|
22
|
-
function _interopRequireWildcard (e, t) { if (typeof WeakMap === 'function') var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; let o; let i; const f = { __proto__: null, default: e }; if (e === null || typeof e !== 'object' && typeof e !== 'function') return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f) } for (const t in e) t !== 'default' && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f })(e, t) }
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
require('core-js/modules/esnext.weak-map.delete-all.js')
|
|
4
|
+
Object.defineProperty(exports, '__esModule', {
|
|
5
|
+
value: true
|
|
6
|
+
})
|
|
7
|
+
exports.build = void 0
|
|
8
|
+
const _bundle = require('./bundle.js')
|
|
9
|
+
const _bundleLint = require('./bundleLint.js')
|
|
10
|
+
const _bundleMinify = require('./bundleMinify.js')
|
|
11
|
+
const _partials = require('./partials.js')
|
|
12
|
+
const _compileReadme = require('./compileReadme.js')
|
|
13
|
+
const _typeDocs = require('./typeDocs.js')
|
|
14
|
+
const _distLint = require('./distLint.js')
|
|
15
|
+
const _distMinify = require('./distMinify.js')
|
|
16
|
+
const _gulp = require('gulp')
|
|
17
|
+
const gulpConfig = _interopRequireWildcard(require('../gulp.config.js'))
|
|
18
|
+
const _copyFonts = require('./copyFonts.js')
|
|
19
|
+
const _images = require('./images.js')
|
|
20
|
+
const _sass = require('./sass.js')
|
|
21
|
+
const _testFull = require('./testFull.js')
|
|
22
|
+
function _interopRequireWildcard (e, t) { if (typeof WeakMap === 'function') var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; let o; let i; const f = { __proto__: null, default: e }; if (e === null || typeof e !== 'object' && typeof e !== 'function') return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f) } for (const t in e) t !== 'default' && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f })(e, t) }
|
|
23
23
|
/**
|
|
24
24
|
* Runs several processes to build and validate the project.
|
|
25
25
|
* Cleans, distributes (lint and minify), bundles (lint and minify), creates the readme, then runs the tests.
|
|
26
26
|
* @memberOf module:js-build-tools
|
|
27
27
|
* @returns {stream.Stream}
|
|
28
|
-
*/
|
|
29
|
-
const build = (done = null) => {
|
|
30
|
-
const distLintMinify = (0, _gulp.parallel)(_distLint.distLint, _distMinify.distMinify)
|
|
31
|
-
const bundleLintMinify = (0, _gulp.parallel)(_bundleLint.bundleLint, _bundleMinify.bundleMinify)
|
|
32
|
-
const buildActions = [(0, _partials.distSeries)(), distLintMinify]
|
|
33
|
-
const generateDocs = gulpConfig.get('docs.enabled')
|
|
34
|
-
if (generateDocs) {
|
|
35
|
-
// The documentation is generated from the TypeScript source itself, the readme is written by hand
|
|
36
|
-
buildActions.push(_typeDocs.typeDocs)
|
|
37
|
-
} else if (gulpConfig.get('typescript.enabled')) {
|
|
38
|
-
// For ts usage, we need to run the readme on the dist directly since that is where the .js files are located
|
|
39
|
-
buildActions.push(_compileReadme.compileReadme)
|
|
40
|
-
}
|
|
41
|
-
if (gulpConfig.get('browser.enabled')) {
|
|
42
|
-
// If not 'nodeOnly' then we also want to bundle for browser after we complete the dist directory
|
|
43
|
-
buildActions.push(_bundle.bundle)
|
|
44
|
-
buildActions.push(bundleLintMinify)
|
|
45
|
-
}
|
|
46
|
-
const runActions = [(0, _gulp.series)(...buildActions)]
|
|
47
|
-
if (!generateDocs && !gulpConfig.get('typescript.enabled')) {
|
|
48
|
-
// Since we didn't run this in series after dist because of typescript, we need to run it now. Potentially faster here.
|
|
49
|
-
runActions.push(_compileReadme.compileReadme)
|
|
50
|
-
}
|
|
51
|
-
runActions.push(_testFull.testFull)
|
|
52
|
-
if (gulpConfig.get('fonts.enabled')) {
|
|
53
|
-
// Conditionally add Fonts process
|
|
54
|
-
runActions.push(_copyFonts.copyFonts)
|
|
55
|
-
}
|
|
56
|
-
if (gulpConfig.get('images.enabled')) {
|
|
57
|
-
// Conditionally add Images process
|
|
58
|
-
runActions.push(_images.images)
|
|
59
|
-
}
|
|
60
|
-
if (gulpConfig.get('sass.enabled')) {
|
|
61
|
-
// Conditionally add SASS process
|
|
62
|
-
runActions.push(_sass.sass)
|
|
63
|
-
}
|
|
64
|
-
// clean has to finish before anything writes into the output folders - images, fonts and sass all write into
|
|
65
|
-
// browser/, so running clean in parallel with them races (ENOTEMPTY errors from clean, or output deleted mid-write).
|
|
66
|
-
return (0, _gulp.series)(_partials.clean, (0, _gulp.parallel)(...runActions))(done)
|
|
67
|
-
}
|
|
68
|
-
exports.build = build
|
|
28
|
+
*/
|
|
29
|
+
const build = (done = null) => {
|
|
30
|
+
const distLintMinify = (0, _gulp.parallel)(_distLint.distLint, _distMinify.distMinify)
|
|
31
|
+
const bundleLintMinify = (0, _gulp.parallel)(_bundleLint.bundleLint, _bundleMinify.bundleMinify)
|
|
32
|
+
const buildActions = [(0, _partials.distSeries)(), distLintMinify]
|
|
33
|
+
const generateDocs = gulpConfig.get('docs.enabled')
|
|
34
|
+
if (generateDocs) {
|
|
35
|
+
// The documentation is generated from the TypeScript source itself, the readme is written by hand
|
|
36
|
+
buildActions.push(_typeDocs.typeDocs)
|
|
37
|
+
} else if (gulpConfig.get('typescript.enabled')) {
|
|
38
|
+
// For ts usage, we need to run the readme on the dist directly since that is where the .js files are located
|
|
39
|
+
buildActions.push(_compileReadme.compileReadme)
|
|
40
|
+
}
|
|
41
|
+
if (gulpConfig.get('browser.enabled')) {
|
|
42
|
+
// If not 'nodeOnly' then we also want to bundle for browser after we complete the dist directory
|
|
43
|
+
buildActions.push(_bundle.bundle)
|
|
44
|
+
buildActions.push(bundleLintMinify)
|
|
45
|
+
}
|
|
46
|
+
const runActions = [(0, _gulp.series)(...buildActions)]
|
|
47
|
+
if (!generateDocs && !gulpConfig.get('typescript.enabled')) {
|
|
48
|
+
// Since we didn't run this in series after dist because of typescript, we need to run it now. Potentially faster here.
|
|
49
|
+
runActions.push(_compileReadme.compileReadme)
|
|
50
|
+
}
|
|
51
|
+
runActions.push(_testFull.testFull)
|
|
52
|
+
if (gulpConfig.get('fonts.enabled')) {
|
|
53
|
+
// Conditionally add Fonts process
|
|
54
|
+
runActions.push(_copyFonts.copyFonts)
|
|
55
|
+
}
|
|
56
|
+
if (gulpConfig.get('images.enabled')) {
|
|
57
|
+
// Conditionally add Images process
|
|
58
|
+
runActions.push(_images.images)
|
|
59
|
+
}
|
|
60
|
+
if (gulpConfig.get('sass.enabled')) {
|
|
61
|
+
// Conditionally add SASS process
|
|
62
|
+
runActions.push(_sass.sass)
|
|
63
|
+
}
|
|
64
|
+
// clean has to finish before anything writes into the output folders - images, fonts and sass all write into
|
|
65
|
+
// browser/, so running clean in parallel with them races (ENOTEMPTY errors from clean, or output deleted mid-write).
|
|
66
|
+
return (0, _gulp.series)(_partials.clean, (0, _gulp.parallel)(...runActions))(done)
|
|
67
|
+
}
|
|
68
|
+
exports.build = build
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.loadImagemin = exports.imagesFor = void 0;
|
|
8
|
-
var _gulpCache = _interopRequireDefault(require("gulp-cache"));
|
|
9
|
-
var
|
|
10
|
-
var _gulp = require("gulp");
|
|
11
|
-
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
12
|
-
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
13
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
14
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
const installHint = 'Add it to your project with: npm install --save-dev github:jheagle/gulp-imagemin#common-js-compatibility ' + '(the CommonJS-compatible fork - upstream gulp-imagemin is ESM-only and cannot be require()d by this package\'s CommonJS build).';
|
|
16
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.loadImagemin = exports.imagesFor = void 0;
|
|
8
|
+
var _gulpCache = _interopRequireDefault(require("gulp-cache"));
|
|
9
|
+
var _loadPeer = require("./loadPeer.js");
|
|
10
|
+
var _gulp = require("gulp");
|
|
11
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
12
|
+
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
13
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
const installHint = 'Add it to your project with: npm install --save-dev github:jheagle/gulp-imagemin#common-js-compatibility ' + '(the CommonJS-compatible fork - upstream gulp-imagemin is ESM-only and cannot be require()d by this package\'s CommonJS build).';
|
|
16
|
+
|
|
17
17
|
/**
|
|
18
18
|
* Load `gulp-imagemin`, an optional peer dependency: image optimization is off by default and its binary-download
|
|
19
19
|
* dependency chain is heavy, so it is only required once the images task actually runs, and it is resolved from the
|
|
@@ -22,42 +22,36 @@ const installHint = 'Add it to your project with: npm install --save-dev github:
|
|
|
22
22
|
* @param {string} [projectPath=process.cwd()] - The project directory to resolve `gulp-imagemin` from.
|
|
23
23
|
* @returns {Function} The gulp-imagemin plugin factory.
|
|
24
24
|
* @throws {Error} With install instructions when gulp-imagemin is missing or is the ESM-only upstream release.
|
|
25
|
-
*/
|
|
26
|
-
const loadImagemin = (projectPath = process.cwd()) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
throw error;
|
|
38
|
-
}
|
|
39
|
-
return loaded && (loaded.__esModule || loaded.default) ? loaded.default : loaded;
|
|
40
|
-
};
|
|
41
|
-
|
|
25
|
+
*/
|
|
26
|
+
const loadImagemin = (projectPath = process.cwd()) => {
|
|
27
|
+
const loaded = (0, _loadPeer.requirePeer)('gulp-imagemin', {
|
|
28
|
+
task: 'images',
|
|
29
|
+
installHint,
|
|
30
|
+
esmOnlyMessage: `gulp-imagemin could not be loaded because it is ESM-only. ${installHint}`,
|
|
31
|
+
projectPath
|
|
32
|
+
});
|
|
33
|
+
return loaded && (loaded.__esModule || loaded.default) ? loaded.default : loaded;
|
|
34
|
+
};
|
|
35
|
+
|
|
42
36
|
/**
|
|
43
37
|
* Move and optimize images into the browser directory.
|
|
44
38
|
* @memberOf module:partials
|
|
45
39
|
* @param {string|array} [imageSrc=src/images/pattern]
|
|
46
40
|
* @param {string} [imageDest=dest/image/folder]
|
|
47
41
|
* @return {stream.Stream}
|
|
48
|
-
*/
|
|
49
|
-
exports.loadImagemin = loadImagemin;
|
|
50
|
-
const imagesFor = (imageSrc = gulpConfig.get('images.from'), imageDest = gulpConfig.get('images.to')) => {
|
|
51
|
-
const imagemin = loadImagemin();
|
|
52
|
-
// Gulp 5 reads files as utf8 text unless told otherwise, which corrupts binary images (and makes gulp-cache drop them).
|
|
53
|
-
return (0, _gulp.src)(imageSrc, {
|
|
54
|
-
encoding: false
|
|
55
|
-
}).pipe(
|
|
56
|
-
// Caching images that ran through imagemin
|
|
57
|
-
(0, _gulpCache.default)(imagemin({
|
|
58
|
-
interlaced: true,
|
|
59
|
-
silent: true,
|
|
60
|
-
verbose: false
|
|
61
|
-
}))).pipe((0, _gulp.dest)(imageDest));
|
|
62
|
-
};
|
|
42
|
+
*/
|
|
43
|
+
exports.loadImagemin = loadImagemin;
|
|
44
|
+
const imagesFor = (imageSrc = gulpConfig.get('images.from'), imageDest = gulpConfig.get('images.to')) => {
|
|
45
|
+
const imagemin = loadImagemin();
|
|
46
|
+
// Gulp 5 reads files as utf8 text unless told otherwise, which corrupts binary images (and makes gulp-cache drop them).
|
|
47
|
+
return (0, _gulp.src)(imageSrc, {
|
|
48
|
+
encoding: false
|
|
49
|
+
}).pipe(
|
|
50
|
+
// Caching images that ran through imagemin
|
|
51
|
+
(0, _gulpCache.default)(imagemin({
|
|
52
|
+
interlaced: true,
|
|
53
|
+
silent: true,
|
|
54
|
+
verbose: false
|
|
55
|
+
}))).pipe((0, _gulp.dest)(imageDest));
|
|
56
|
+
};
|
|
63
57
|
exports.imagesFor = imagesFor;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.requirePeer = exports.importPeer = exports.importModule = void 0;
|
|
7
|
+
require("core-js/modules/es.array.includes.js");
|
|
8
|
+
var _nodeModule = require("node:module");
|
|
9
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
10
|
+
var _nodeUrl = require("node:url");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
// Several dependencies ship ESM-only (standard, gulp-ts-compile, typedoc), but this package also publishes a CommonJS
|
|
13
|
+
// build (dist/*.js) whose babel transform would turn even a dynamic import() into a require() that cannot load an ES
|
|
14
|
+
// module. Hiding the import() inside a Function constructor keeps it a genuine dynamic import that works from either
|
|
15
|
+
// build, because babel cannot see (and so cannot rewrite) an import expression which only exists as a runtime string.
|
|
16
|
+
const dynamicImport = new Function('specifier', 'return import(specifier)');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Import an ES module (or any module) with a real dynamic import(), whichever build (ESM or CommonJS) this runs from.
|
|
20
|
+
* @memberOf module:partials
|
|
21
|
+
* @param {string} specifier - The package name, or the URL of a file.
|
|
22
|
+
* @returns {Promise<Object>} The module namespace.
|
|
23
|
+
*/
|
|
24
|
+
const importModule = specifier => dynamicImport(specifier);
|
|
25
|
+
exports.importModule = importModule;
|
|
26
|
+
const isMissing = (error, name) => error.code === 'MODULE_NOT_FOUND' && error.message.includes(`'${name}'`);
|
|
27
|
+
const notInstalled = (name, {
|
|
28
|
+
task,
|
|
29
|
+
installHint
|
|
30
|
+
}) => new Error(`The ${task} task needs the optional peer dependency ${name}, which is not installed. ${installHint}`);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Load an optional peer dependency (one which is only needed once a task runs, so projects which never use that task
|
|
34
|
+
* do not have to install it) with require(), from the project being built rather than from this package. When it is
|
|
35
|
+
* missing the error explains how to install it.
|
|
36
|
+
* @memberOf module:partials
|
|
37
|
+
* @param {string} name - The package name.
|
|
38
|
+
* @param {Object} options
|
|
39
|
+
* @param {string} options.task - The task which needs the package, for the error message.
|
|
40
|
+
* @param {string} options.installHint - How to install it, for the error message.
|
|
41
|
+
* @param {string} [options.esmOnlyMessage] - The error message when the package turns out to be ESM-only (it cannot be require()d).
|
|
42
|
+
* @param {string} [options.projectPath=process.cwd()] - The folder of the project (which has the package.json) being built.
|
|
43
|
+
* @returns {*} Whatever the package exports.
|
|
44
|
+
* @throws {Error} With install instructions when the package is not installed.
|
|
45
|
+
*/
|
|
46
|
+
const requirePeer = (name, {
|
|
47
|
+
task,
|
|
48
|
+
installHint,
|
|
49
|
+
esmOnlyMessage,
|
|
50
|
+
projectPath = process.cwd()
|
|
51
|
+
}) => {
|
|
52
|
+
try {
|
|
53
|
+
return (0, _nodeModule.createRequire)(_nodePath.default.join(projectPath, 'package.json'))(name);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
if (isMissing(error, name)) {
|
|
56
|
+
throw notInstalled(name, {
|
|
57
|
+
task,
|
|
58
|
+
installHint
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (error.code === 'ERR_REQUIRE_ESM' && esmOnlyMessage) {
|
|
62
|
+
throw new Error(esmOnlyMessage);
|
|
63
|
+
}
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Import an optional peer dependency which ships ESM-only, from the project being built. See {@link requirePeer}.
|
|
70
|
+
* @memberOf module:partials
|
|
71
|
+
* @param {string} name - The package name.
|
|
72
|
+
* @param {Object} options
|
|
73
|
+
* @param {string} options.task - The task which needs the package, for the error message.
|
|
74
|
+
* @param {string} options.installHint - How to install it, for the error message.
|
|
75
|
+
* @param {string} [options.projectPath=process.cwd()] - The folder of the project (which has the package.json) being built.
|
|
76
|
+
* @returns {Promise<Object>} The module namespace.
|
|
77
|
+
* @throws {Error} With install instructions when the package is not installed.
|
|
78
|
+
*/
|
|
79
|
+
exports.requirePeer = requirePeer;
|
|
80
|
+
const importPeer = async (name, {
|
|
81
|
+
task,
|
|
82
|
+
installHint,
|
|
83
|
+
projectPath = process.cwd()
|
|
84
|
+
}) => {
|
|
85
|
+
let resolved;
|
|
86
|
+
try {
|
|
87
|
+
resolved = (0, _nodeModule.createRequire)(_nodePath.default.join(projectPath, 'package.json')).resolve(name);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
if (isMissing(error, name)) {
|
|
90
|
+
throw notInstalled(name, {
|
|
91
|
+
task,
|
|
92
|
+
installHint
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
return importModule((0, _nodeUrl.pathToFileURL)(resolved).href);
|
|
98
|
+
};
|
|
99
|
+
exports.importPeer = importPeer;
|
|
@@ -1,40 +1,38 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.standardLint = void 0;
|
|
7
|
-
require("core-js/modules/esnext.iterator.constructor.js");
|
|
8
|
-
require("core-js/modules/esnext.iterator.for-each.js");
|
|
9
|
-
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
10
|
-
var _through = _interopRequireDefault(require("through2"));
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const importStandard = new Function('return import(\'standard\')');
|
|
17
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.standardLint = void 0;
|
|
7
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
8
|
+
require("core-js/modules/esnext.iterator.for-each.js");
|
|
9
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
10
|
+
var _through = _interopRequireDefault(require("through2"));
|
|
11
|
+
var _loadPeer = require("./loadPeer.js");
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
// `standard` (17+) ships ESM-only, see importModule for how it is imported.
|
|
14
|
+
const importStandard = () => (0, _loadPeer.importModule)('standard');
|
|
15
|
+
|
|
18
16
|
/**
|
|
19
17
|
* Print a file's lint messages, if it has any.
|
|
20
18
|
* @memberOf module:partials
|
|
21
19
|
* @param {import('vinyl')} file
|
|
22
20
|
* @param {{messages: Array<{line: number, column: number, message: string}>, errorCount: number, warningCount: number}} result
|
|
23
21
|
* @returns {undefined}
|
|
24
|
-
*/
|
|
25
|
-
const printFileReport = (file, result) => {
|
|
26
|
-
if (!result.messages.length) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
console.log(_nodePath.default.relative(file.cwd, file.path));
|
|
30
|
-
result.messages.forEach(({
|
|
31
|
-
line,
|
|
32
|
-
column,
|
|
33
|
-
message
|
|
34
|
-
}) => console.log(`line ${line}:${column}\t${message}`));
|
|
35
|
-
console.log(`✖ ${result.errorCount} error\t⚠ ${result.warningCount} warning\n`);
|
|
36
|
-
};
|
|
37
|
-
|
|
22
|
+
*/
|
|
23
|
+
const printFileReport = (file, result) => {
|
|
24
|
+
if (!result.messages.length) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
console.log(_nodePath.default.relative(file.cwd, file.path));
|
|
28
|
+
result.messages.forEach(({
|
|
29
|
+
line,
|
|
30
|
+
column,
|
|
31
|
+
message
|
|
32
|
+
}) => console.log(`line ${line}:${column}\t${message}`));
|
|
33
|
+
console.log(`✖ ${result.errorCount} error\t⚠ ${result.warningCount} warning\n`);
|
|
34
|
+
};
|
|
35
|
+
|
|
38
36
|
/**
|
|
39
37
|
* Lint every file streaming through with JavaScript Standard Style and, unless `fix` is false, apply the automatic
|
|
40
38
|
* fixes to the file's contents so a following `dest()` writes the fixed version. Remaining problems are printed
|
|
@@ -49,48 +47,48 @@ const printFileReport = (file, result) => {
|
|
|
49
47
|
* should never need to pass this - it exists so tests can supply a stand-in, since this project's
|
|
50
48
|
* CommonJS-transform-based Jest setup cannot execute a real dynamic import() of an ES module.
|
|
51
49
|
* @returns {import('stream').Transform}
|
|
52
|
-
*/
|
|
53
|
-
const standardLint = ({
|
|
54
|
-
fix = true
|
|
55
|
-
} = {}, loadStandard = () => importStandard().then(({
|
|
56
|
-
default: standard
|
|
57
|
-
}) => standard)) => {
|
|
58
|
-
const totals = {
|
|
59
|
-
errors: 0,
|
|
60
|
-
warnings: 0
|
|
61
|
-
};
|
|
62
|
-
return _through.default.obj(function (file, enc, callback) {
|
|
63
|
-
if (file.isNull()) {
|
|
64
|
-
callback(null, file);
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
if (file.isStream()) {
|
|
68
|
-
callback(new Error('standardLint: streaming file contents are not supported.'));
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
loadStandard().then(standard => standard.lintText(file.contents.toString(), {
|
|
72
|
-
filename: file.path,
|
|
73
|
-
cwd: file.cwd,
|
|
74
|
-
fix
|
|
75
|
-
})).then(results => {
|
|
76
|
-
// No result at all means the file is ignored by the project's Standard configuration.
|
|
77
|
-
const [result] = results;
|
|
78
|
-
if (result) {
|
|
79
|
-
if (typeof result.output === 'string') {
|
|
80
|
-
file.contents = Buffer.from(result.output);
|
|
81
|
-
}
|
|
82
|
-
totals.errors += result.errorCount;
|
|
83
|
-
totals.warnings += result.warningCount;
|
|
84
|
-
printFileReport(file, result);
|
|
85
|
-
}
|
|
86
|
-
callback(null, file);
|
|
87
|
-
}, callback);
|
|
88
|
-
}, function (callback) {
|
|
89
|
-
console.log('Standard linter results');
|
|
90
|
-
console.log('======================================');
|
|
91
|
-
console.log(`✖ Errors total: ${totals.errors}`);
|
|
92
|
-
console.log(`⚠ Warnings total: ${totals.warnings}\n`);
|
|
93
|
-
callback();
|
|
94
|
-
});
|
|
95
|
-
};
|
|
50
|
+
*/
|
|
51
|
+
const standardLint = ({
|
|
52
|
+
fix = true
|
|
53
|
+
} = {}, loadStandard = () => importStandard().then(({
|
|
54
|
+
default: standard
|
|
55
|
+
}) => standard)) => {
|
|
56
|
+
const totals = {
|
|
57
|
+
errors: 0,
|
|
58
|
+
warnings: 0
|
|
59
|
+
};
|
|
60
|
+
return _through.default.obj(function (file, enc, callback) {
|
|
61
|
+
if (file.isNull()) {
|
|
62
|
+
callback(null, file);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (file.isStream()) {
|
|
66
|
+
callback(new Error('standardLint: streaming file contents are not supported.'));
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
loadStandard().then(standard => standard.lintText(file.contents.toString(), {
|
|
70
|
+
filename: file.path,
|
|
71
|
+
cwd: file.cwd,
|
|
72
|
+
fix
|
|
73
|
+
})).then(results => {
|
|
74
|
+
// No result at all means the file is ignored by the project's Standard configuration.
|
|
75
|
+
const [result] = results;
|
|
76
|
+
if (result) {
|
|
77
|
+
if (typeof result.output === 'string') {
|
|
78
|
+
file.contents = Buffer.from(result.output);
|
|
79
|
+
}
|
|
80
|
+
totals.errors += result.errorCount;
|
|
81
|
+
totals.warnings += result.warningCount;
|
|
82
|
+
printFileReport(file, result);
|
|
83
|
+
}
|
|
84
|
+
callback(null, file);
|
|
85
|
+
}, callback);
|
|
86
|
+
}, function (callback) {
|
|
87
|
+
console.log('Standard linter results');
|
|
88
|
+
console.log('======================================');
|
|
89
|
+
console.log(`✖ Errors total: ${totals.errors}`);
|
|
90
|
+
console.log(`⚠ Warnings total: ${totals.warnings}\n`);
|
|
91
|
+
callback();
|
|
92
|
+
});
|
|
93
|
+
};
|
|
96
94
|
exports.standardLint = standardLint;
|