js-build-tools 5.6.0 → 6.0.0
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 +98 -3
- package/dist/build.js +65 -64
- package/dist/build.min.js +1 -1
- package/dist/bundle.js +40 -40
- package/dist/bundleMinify.js +18 -18
- package/dist/compileReadme.js +7 -7
- package/dist/copyFonts.js +10 -10
- package/dist/default.js +12 -12
- package/dist/dist.js +7 -7
- package/dist/distMinify.js +10 -10
- package/dist/images.js +7 -7
- package/dist/partials/addToReadme.js +14 -3
- package/dist/partials/imagesFor.js +42 -42
- package/dist/partials/loadPeer.js +70 -70
- package/dist/partials/neostandardLint.js +144 -0
- package/dist/partials/tsFor.js +70 -70
- package/dist/partials/typeDocsFor.js +202 -202
- package/dist/partials.js +136 -136
- package/dist/partials.min.js +1 -1
- package/dist/sass.js +7 -7
- package/dist/sourceLint.js +33 -0
- package/dist/sourceLint.min.js +1 -0
- package/dist/test-helpers/neostandardLintWithRealNeostandard.js +48 -0
- package/dist/test-helpers/setUp.js +5 -0
- package/dist/testFull.js +13 -13
- package/dist/testHelpers.js +8 -8
- package/dist/testQuick.js +13 -13
- package/dist/typeDocs.js +9 -9
- package/dist/typeScript.js +6 -6
- package/dist/utilities/convertMjsFilesForDocs.js +48 -0
- package/dist/utilities/esmNamedExportsToCjs.js +33 -0
- package/dist/utilities/getBundleConfigs.js +27 -27
- package/dist/watchFull.js +7 -7
- package/dist/watchTest.js +11 -11
- package/functions/build.mjs +9 -8
- package/functions/build.test.mjs +18 -25
- package/functions/partials/addToReadme.mjs +14 -5
- package/functions/partials/neostandardLint.mjs +118 -0
- package/functions/partials/neostandardLint.test.mjs +109 -0
- package/functions/partials.mjs +1 -1
- package/functions/sourceLint.mjs +24 -0
- package/functions/sourceLint.test.mjs +73 -0
- package/functions/test-helpers/neostandardLintWithRealNeostandard.mjs +38 -0
- package/functions/test-helpers/setUp.mjs +5 -0
- package/functions/utilities/convertMjsFilesForDocs.mjs +33 -0
- package/functions/utilities/convertMjsFilesForDocs.test.mjs +57 -0
- package/functions/utilities/esmNamedExportsToCjs.mjs +29 -0
- package/functions/utilities/esmNamedExportsToCjs.test.mjs +47 -0
- package/gulp.config.mjs +4 -0
- package/gulpfile.base.js +2 -4
- package/gulpfile.base.mjs +1 -2
- package/package.json +7 -6
- package/dist/bundleLint.js +0 -28
- package/dist/bundleLint.min.js +0 -1
- package/dist/distLint.js +0 -20
- package/dist/distLint.min.js +0 -1
- package/dist/partials/standardLint.js +0 -94
- package/dist/test-helpers/standardLintWithRealStandard.js +0 -28
- package/functions/bundleLint.mjs +0 -18
- package/functions/bundleLint.test.mjs +0 -85
- package/functions/distLint.mjs +0 -12
- package/functions/distLint.test.mjs +0 -62
- package/functions/partials/standardLint.mjs +0 -78
- package/functions/partials/standardLint.test.mjs +0 -99
- package/functions/test-helpers/standardLintWithRealStandard.mjs +0 -21
package/dist/images.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports,
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.images = void 0
|
|
7
|
-
|
|
5
|
+
});
|
|
6
|
+
exports.images = void 0;
|
|
7
|
+
var _imagesFor = require("./partials/imagesFor.js");
|
|
8
8
|
/**
|
|
9
9
|
* Move and optimize the images into the browser folder using configured settings.
|
|
10
10
|
* @memberOf module:js-build-tools
|
|
11
11
|
* @return {stream.Stream}
|
|
12
12
|
*/
|
|
13
|
-
const images = () => (0, _imagesFor.imagesFor)()
|
|
14
|
-
exports.images = images
|
|
13
|
+
const images = () => (0, _imagesFor.imagesFor)();
|
|
14
|
+
exports.images = images;
|
|
@@ -9,15 +9,26 @@ var _fs = _interopRequireDefault(require("fs"));
|
|
|
9
9
|
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
10
10
|
var _jsdocToMarkdown = _interopRequireDefault(require("jsdoc-to-markdown"));
|
|
11
11
|
var _glob = require("glob");
|
|
12
|
+
var _convertMjsFilesForDocs = require("../utilities/convertMjsFilesForDocs.js");
|
|
12
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); }
|
|
13
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
15
|
/**
|
|
15
16
|
* Appends all the jsdoc comments to the readme file. Assumes empty or templated file.
|
|
16
17
|
* Configure this with 'readmeSearch', 'readmePath', 'readmeFile', and 'readmeOptions'.
|
|
18
|
+
*
|
|
19
|
+
* jsdoc-to-markdown only recognizes `.js` files, even though it parses real ESM syntax just fine once it reads
|
|
20
|
+
* one - `readme.fromEsm` (empty by default) names `.mjs` files to include anyway, converted on the fly (see
|
|
21
|
+
* {@link convertMjsFilesForDocs}) and cleaned up again once this has read them, win or lose.
|
|
17
22
|
* @memberOf module:partials
|
|
18
23
|
* @returns {string|Uint8Array}
|
|
19
24
|
*/
|
|
20
|
-
const addToReadme = () =>
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
const addToReadme = () => {
|
|
26
|
+
const {
|
|
27
|
+
filePaths: esmFilePaths,
|
|
28
|
+
cleanUp
|
|
29
|
+
} = (0, _convertMjsFilesForDocs.convertMjsFilesForDocs)((0, _glob.globSync)(gulpConfig.get('readme.fromEsm') || []));
|
|
30
|
+
return _jsdocToMarkdown.default.render({
|
|
31
|
+
files: [...(0, _glob.globSync)(gulpConfig.get('readme.from')), ...esmFilePaths]
|
|
32
|
+
}).finally(cleanUp).then(readme => _fs.default.appendFileSync(gulpConfig.get('readme.to') + gulpConfig.get('readme.file'), readme, gulpConfig.get('readmeOptions')));
|
|
33
|
+
};
|
|
23
34
|
exports.addToReadme = addToReadme;
|
|
@@ -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 _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
|
-
|
|
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,36 +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
|
-
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
|
-
|
|
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
|
+
|
|
36
36
|
/**
|
|
37
37
|
* Move and optimize images into the browser directory.
|
|
38
38
|
* @memberOf module:partials
|
|
39
39
|
* @param {string|array} [imageSrc=src/images/pattern]
|
|
40
40
|
* @param {string} [imageDest=dest/image/folder]
|
|
41
41
|
* @return {stream.Stream}
|
|
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
|
-
};
|
|
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
|
+
};
|
|
57
57
|
exports.imagesFor = imagesFor;
|
|
@@ -1,34 +1,34 @@
|
|
|
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
|
-
|
|
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
18
|
/**
|
|
19
19
|
* Import an ES module (or any module) with a real dynamic import(), whichever build (ESM or CommonJS) this runs from.
|
|
20
20
|
* @memberOf module:partials
|
|
21
21
|
* @param {string} specifier - The package name, or the URL of a file.
|
|
22
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
|
-
|
|
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
32
|
/**
|
|
33
33
|
* Load an optional peer dependency (one which is only needed once a task runs, so projects which never use that task
|
|
34
34
|
* do not have to install it) with require(), from the project being built rather than from this package. When it is
|
|
@@ -42,29 +42,29 @@ const notInstalled = (name, {
|
|
|
42
42
|
* @param {string} [options.projectPath=process.cwd()] - The folder of the project (which has the package.json) being built.
|
|
43
43
|
* @returns {*} Whatever the package exports.
|
|
44
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
|
-
|
|
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
68
|
/**
|
|
69
69
|
* Import an optional peer dependency which ships ESM-only, from the project being built. See {@link requirePeer}.
|
|
70
70
|
* @memberOf module:partials
|
|
@@ -75,25 +75,25 @@ const requirePeer = (name, {
|
|
|
75
75
|
* @param {string} [options.projectPath=process.cwd()] - The folder of the project (which has the package.json) being built.
|
|
76
76
|
* @returns {Promise<Object>} The module namespace.
|
|
77
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
|
-
};
|
|
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
99
|
exports.importPeer = importPeer;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.neostandardLint = void 0;
|
|
7
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
8
|
+
require("core-js/modules/esnext.iterator.for-each.js");
|
|
9
|
+
var _nodeFs = _interopRequireDefault(require("node:fs"));
|
|
10
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
11
|
+
var _through = _interopRequireDefault(require("through2"));
|
|
12
|
+
var _eslint = require("eslint");
|
|
13
|
+
var _loadPeer = require("./loadPeer.js");
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
// neostandard (js-build-tools' chosen style - a maintained, TypeScript-aware successor to `standard`, see
|
|
16
|
+
// https://github.com/neostandard/neostandard) ships ESM-only, see importModule for how it is imported.
|
|
17
|
+
const importNeostandard = () => (0, _loadPeer.importModule)('neostandard').then(({
|
|
18
|
+
neostandard
|
|
19
|
+
}) => neostandard);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Read the `env` a project already declared for Standard (the `standard` field in its package.json), so a project
|
|
23
|
+
* migrating from `standard` keeps its globals (jest, browser, ...) without touching package.json.
|
|
24
|
+
* @param {string} cwd
|
|
25
|
+
* @returns {Array<string>}
|
|
26
|
+
*/
|
|
27
|
+
const readEnv = cwd => {
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(_nodeFs.default.readFileSync(_nodePath.default.join(cwd, 'package.json'), 'utf8')).standard?.env ?? [];
|
|
30
|
+
} catch {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Build an ESLint instance configured with neostandard, honoring the project's own package.json `standard.env`.
|
|
37
|
+
* @param {Object} options
|
|
38
|
+
* @param {string} options.cwd
|
|
39
|
+
* @param {boolean} options.ts
|
|
40
|
+
* @param {boolean} options.fix
|
|
41
|
+
* @returns {Promise<import('eslint').ESLint>}
|
|
42
|
+
*/
|
|
43
|
+
const buildEslint = async ({
|
|
44
|
+
cwd,
|
|
45
|
+
ts,
|
|
46
|
+
fix
|
|
47
|
+
}) => {
|
|
48
|
+
const neostandard = await importNeostandard();
|
|
49
|
+
return new _eslint.ESLint({
|
|
50
|
+
cwd,
|
|
51
|
+
fix,
|
|
52
|
+
overrideConfigFile: true,
|
|
53
|
+
baseConfig: neostandard({
|
|
54
|
+
ts,
|
|
55
|
+
env: readEnv(cwd)
|
|
56
|
+
})
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Print a file's lint messages, if it has any.
|
|
62
|
+
* @memberOf module:partials
|
|
63
|
+
* @param {import('vinyl')} file
|
|
64
|
+
* @param {{messages: Array<{line: number, column: number, message: string}>, errorCount: number, warningCount: number}} result
|
|
65
|
+
* @returns {undefined}
|
|
66
|
+
*/
|
|
67
|
+
const printFileReport = (file, result) => {
|
|
68
|
+
if (!result.messages.length) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
console.log(_nodePath.default.relative(file.cwd, file.path));
|
|
72
|
+
result.messages.forEach(({
|
|
73
|
+
line,
|
|
74
|
+
column,
|
|
75
|
+
message
|
|
76
|
+
}) => console.log(`line ${line}:${column}\t${message}`));
|
|
77
|
+
console.log(`✖ ${result.errorCount} error\t⚠ ${result.warningCount} warning\n`);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Lint every file streaming through with neostandard and, unless `fix` is false, apply the automatic fixes to the
|
|
82
|
+
* file's contents so a following `dest()` writes the fixed version. Remaining problems are printed along with a
|
|
83
|
+
* summary once the stream ends; they never fail the build.
|
|
84
|
+
*
|
|
85
|
+
* One ESLint instance is built from the first file's own cwd and reused for the rest of the stream, since every
|
|
86
|
+
* file in a given lint pass shares the same project (and so the same config).
|
|
87
|
+
* @memberOf module:partials
|
|
88
|
+
* @param {Object} [options={}]
|
|
89
|
+
* @param {boolean} [options.fix=true] - Apply neostandard's automatic fixes to the file contents.
|
|
90
|
+
* @param {boolean} [options.ts=false] - Lint `.ts` files too, with type-aware rules (see neostandard's `ts` option).
|
|
91
|
+
* @param {function(Object): Promise<{lintText: Function}>} [loadEslint] - Resolves an ESLint-shaped linter. Real
|
|
92
|
+
* callers should never need to pass this - it exists so tests can supply a stand-in, since this project's
|
|
93
|
+
* CommonJS-transform-based Jest setup cannot execute a real dynamic import() of neostandard (ESM-only).
|
|
94
|
+
* @returns {import('stream').Transform}
|
|
95
|
+
*/
|
|
96
|
+
const neostandardLint = ({
|
|
97
|
+
fix = true,
|
|
98
|
+
ts = false
|
|
99
|
+
} = {}, loadEslint = buildEslint) => {
|
|
100
|
+
const totals = {
|
|
101
|
+
errors: 0,
|
|
102
|
+
warnings: 0
|
|
103
|
+
};
|
|
104
|
+
let eslintPromise = null;
|
|
105
|
+
return _through.default.obj(function (file, enc, callback) {
|
|
106
|
+
if (file.isNull()) {
|
|
107
|
+
callback(null, file);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (file.isStream()) {
|
|
111
|
+
callback(new Error('neostandardLint: streaming file contents are not supported.'));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (!eslintPromise) {
|
|
115
|
+
eslintPromise = loadEslint({
|
|
116
|
+
cwd: file.cwd,
|
|
117
|
+
ts,
|
|
118
|
+
fix
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
eslintPromise.then(eslint => eslint.lintText(file.contents.toString(), {
|
|
122
|
+
filePath: file.path
|
|
123
|
+
})).then(results => {
|
|
124
|
+
// No result at all means the file is ignored by the project's ESLint configuration.
|
|
125
|
+
const [result] = results;
|
|
126
|
+
if (result) {
|
|
127
|
+
if (typeof result.output === 'string') {
|
|
128
|
+
file.contents = Buffer.from(result.output);
|
|
129
|
+
}
|
|
130
|
+
totals.errors += result.errorCount;
|
|
131
|
+
totals.warnings += result.warningCount;
|
|
132
|
+
printFileReport(file, result);
|
|
133
|
+
}
|
|
134
|
+
callback(null, file);
|
|
135
|
+
}, callback);
|
|
136
|
+
}, function (callback) {
|
|
137
|
+
console.log('neostandard linter results');
|
|
138
|
+
console.log('======================================');
|
|
139
|
+
console.log(`✖ Errors total: ${totals.errors}`);
|
|
140
|
+
console.log(`⚠ Warnings total: ${totals.warnings}\n`);
|
|
141
|
+
callback();
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
exports.neostandardLint = neostandardLint;
|
package/dist/partials/tsFor.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
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.tsFor = exports.loadTypescript = void 0;
|
|
8
|
-
var _gulp = require("gulp");
|
|
9
|
-
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
10
|
-
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
11
|
-
var _loadPeer = require("./loadPeer.js");
|
|
12
|
-
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); }
|
|
13
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
-
// gulp-ts-compile ships ESM-only (no CJS build - see its own package.json), see importModule for how it is imported.
|
|
15
|
-
const importGulpTsCompile = () => (0, _loadPeer.importModule)('gulp-ts-compile');
|
|
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.tsFor = exports.loadTypescript = void 0;
|
|
8
|
+
var _gulp = require("gulp");
|
|
9
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
10
|
+
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
11
|
+
var _loadPeer = require("./loadPeer.js");
|
|
12
|
+
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); }
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
// gulp-ts-compile ships ESM-only (no CJS build - see its own package.json), see importModule for how it is imported.
|
|
15
|
+
const importGulpTsCompile = () => (0, _loadPeer.importModule)('gulp-ts-compile');
|
|
16
|
+
|
|
17
17
|
/**
|
|
18
18
|
* Wrap a stream in a promise that resolves once it finishes writing.
|
|
19
19
|
* @memberOf module:partials
|
|
20
20
|
* @param {import('node:stream').Stream} stream
|
|
21
21
|
* @returns {Promise<void>}
|
|
22
|
-
*/
|
|
23
|
-
const installHint = 'Install it in your project with: npm install --save-dev typescript';
|
|
24
|
-
|
|
22
|
+
*/
|
|
23
|
+
const installHint = 'Install it in your project with: npm install --save-dev typescript';
|
|
24
|
+
|
|
25
25
|
/**
|
|
26
26
|
* Load the project's own copy of TypeScript (an optional peer dependency, only needed when the typescript task is
|
|
27
27
|
* enabled) from the project being built, so projects which do not use TypeScript never need it installed.
|
|
@@ -29,18 +29,18 @@ const installHint = 'Install it in your project with: npm install --save-dev typ
|
|
|
29
29
|
* @param {string} [projectPath=process.cwd()] The folder of the project (which has the package.json) being built.
|
|
30
30
|
* @returns {Object} The TypeScript compiler API module.
|
|
31
31
|
* @throws {Error} With install instructions when typescript is not installed.
|
|
32
|
-
*/
|
|
33
|
-
const loadTypescript = (projectPath = process.cwd()) => (0, _loadPeer.requirePeer)('typescript', {
|
|
34
|
-
task: 'typescript',
|
|
35
|
-
installHint,
|
|
36
|
-
projectPath
|
|
37
|
-
});
|
|
38
|
-
exports.loadTypescript = loadTypescript;
|
|
39
|
-
const streamToPromise = stream => new Promise((resolve, reject) => {
|
|
40
|
-
stream.on('finish', resolve);
|
|
41
|
-
stream.on('error', reject);
|
|
42
|
-
});
|
|
43
|
-
|
|
32
|
+
*/
|
|
33
|
+
const loadTypescript = (projectPath = process.cwd()) => (0, _loadPeer.requirePeer)('typescript', {
|
|
34
|
+
task: 'typescript',
|
|
35
|
+
installHint,
|
|
36
|
+
projectPath
|
|
37
|
+
});
|
|
38
|
+
exports.loadTypescript = loadTypescript;
|
|
39
|
+
const streamToPromise = stream => new Promise((resolve, reject) => {
|
|
40
|
+
stream.on('finish', resolve);
|
|
41
|
+
stream.on('error', reject);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
44
|
/**
|
|
45
45
|
* Read a tsconfig.json file into real typescript.CompilerOptions values, using only TypeScript's stable, current,
|
|
46
46
|
* public config-reading API (the same one `tsc --project` itself uses internally) - never
|
|
@@ -49,13 +49,13 @@ const streamToPromise = stream => new Promise((resolve, reject) => {
|
|
|
49
49
|
* @memberOf module:partials
|
|
50
50
|
* @param {string} configPath - Path to a tsconfig.json file.
|
|
51
51
|
* @returns {import('typescript').CompilerOptions}
|
|
52
|
-
*/
|
|
53
|
-
const readCompilerOptions = (ts, configPath) => {
|
|
54
|
-
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
55
|
-
const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, _nodePath.default.dirname(configPath));
|
|
56
|
-
return parsedConfig.options;
|
|
57
|
-
};
|
|
58
|
-
|
|
52
|
+
*/
|
|
53
|
+
const readCompilerOptions = (ts, configPath) => {
|
|
54
|
+
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
55
|
+
const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, _nodePath.default.dirname(configPath));
|
|
56
|
+
return parsedConfig.options;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
59
|
/**
|
|
60
60
|
* Starting at the source directory, find all the ts files and convert them into the distribution directory.
|
|
61
61
|
* @memberOf module:partials
|
|
@@ -68,36 +68,36 @@ const readCompilerOptions = (ts, configPath) => {
|
|
|
68
68
|
* suite already covers real TypeScript-compile correctness - this function's own tests only need to verify its
|
|
69
69
|
* config resolution and stream wiring.
|
|
70
70
|
* @returns {Function}
|
|
71
|
-
*/
|
|
72
|
-
const tsFor = (srcPath = gulpConfig.get('typescript.from'), distPath = gulpConfig.get('typescript.to'), loadTsCompile = () => importGulpTsCompile().then(({
|
|
73
|
-
default: tsCompile
|
|
74
|
-
}) => tsCompile)) => {
|
|
75
|
-
if (gulpConfig.get('typescript.enabled') === false) {
|
|
76
|
-
return () => {};
|
|
77
|
-
}
|
|
78
|
-
const ts = loadTypescript();
|
|
79
|
-
const configPath = gulpConfig.get('typescript.config');
|
|
80
|
-
// When no tsconfig.json is configured, target/module are pinned explicitly rather than left for TypeScript's
|
|
81
|
-
// own compiler defaults - those defaults have already shifted once across a TypeScript version bump in this
|
|
82
|
-
// project's own history (silently changing whether output keeps `const`/`let` or downlevels to `var`), and
|
|
83
|
-
// pinning them keeps this task's output stable across future TypeScript upgrades too. ES5/CommonJS matches
|
|
84
|
-
// what the downstream babel/browserify bundling pipeline has always assumed it receives.
|
|
85
|
-
const compilerOptions = configPath ? readCompilerOptions(ts, configPath) : {
|
|
86
|
-
declaration: true,
|
|
87
|
-
target: ts.ScriptTarget.ES5,
|
|
88
|
-
module: ts.ModuleKind.CommonJS,
|
|
89
|
-
esModuleInterop: false
|
|
90
|
-
};
|
|
91
|
-
// Accepts gulp's own callback-style task convention (an optional `done`, called once finished) rather than
|
|
92
|
-
// just returning a Promise, since callers may invoke the returned function directly with a callback instead
|
|
93
|
-
// of relying on gulp's own runner to observe a returned Promise.
|
|
94
|
-
return done => {
|
|
95
|
-
const compile = async () => {
|
|
96
|
-
const tsCompile = await loadTsCompile();
|
|
97
|
-
const tsResult = (0, _gulp.src)(srcPath).pipe(tsCompile(compilerOptions));
|
|
98
|
-
await Promise.all([streamToPromise(tsResult.dts.pipe((0, _gulp.dest)(distPath))), streamToPromise(tsResult.js.pipe((0, _gulp.dest)(distPath)))]);
|
|
99
|
-
};
|
|
100
|
-
return typeof done === 'function' ? compile().then(() => done(), done) : compile();
|
|
101
|
-
};
|
|
102
|
-
};
|
|
71
|
+
*/
|
|
72
|
+
const tsFor = (srcPath = gulpConfig.get('typescript.from'), distPath = gulpConfig.get('typescript.to'), loadTsCompile = () => importGulpTsCompile().then(({
|
|
73
|
+
default: tsCompile
|
|
74
|
+
}) => tsCompile)) => {
|
|
75
|
+
if (gulpConfig.get('typescript.enabled') === false) {
|
|
76
|
+
return () => {};
|
|
77
|
+
}
|
|
78
|
+
const ts = loadTypescript();
|
|
79
|
+
const configPath = gulpConfig.get('typescript.config');
|
|
80
|
+
// When no tsconfig.json is configured, target/module are pinned explicitly rather than left for TypeScript's
|
|
81
|
+
// own compiler defaults - those defaults have already shifted once across a TypeScript version bump in this
|
|
82
|
+
// project's own history (silently changing whether output keeps `const`/`let` or downlevels to `var`), and
|
|
83
|
+
// pinning them keeps this task's output stable across future TypeScript upgrades too. ES5/CommonJS matches
|
|
84
|
+
// what the downstream babel/browserify bundling pipeline has always assumed it receives.
|
|
85
|
+
const compilerOptions = configPath ? readCompilerOptions(ts, configPath) : {
|
|
86
|
+
declaration: true,
|
|
87
|
+
target: ts.ScriptTarget.ES5,
|
|
88
|
+
module: ts.ModuleKind.CommonJS,
|
|
89
|
+
esModuleInterop: false
|
|
90
|
+
};
|
|
91
|
+
// Accepts gulp's own callback-style task convention (an optional `done`, called once finished) rather than
|
|
92
|
+
// just returning a Promise, since callers may invoke the returned function directly with a callback instead
|
|
93
|
+
// of relying on gulp's own runner to observe a returned Promise.
|
|
94
|
+
return done => {
|
|
95
|
+
const compile = async () => {
|
|
96
|
+
const tsCompile = await loadTsCompile();
|
|
97
|
+
const tsResult = (0, _gulp.src)(srcPath).pipe(tsCompile(compilerOptions));
|
|
98
|
+
await Promise.all([streamToPromise(tsResult.dts.pipe((0, _gulp.dest)(distPath))), streamToPromise(tsResult.js.pipe((0, _gulp.dest)(distPath)))]);
|
|
99
|
+
};
|
|
100
|
+
return typeof done === 'function' ? compile().then(() => done(), done) : compile();
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
103
|
exports.tsFor = tsFor;
|