js-build-tools 5.7.0 → 6.1.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.
Files changed (82) hide show
  1. package/README.md +46 -3
  2. package/dist/build.js +40 -38
  3. package/dist/build.min.js +1 -1
  4. package/dist/bundle.js +24 -23
  5. package/dist/bundle.min.js +1 -1
  6. package/dist/bundleMinify.js +14 -13
  7. package/dist/bundleMinify.min.js +1 -1
  8. package/dist/compileReadme.js +7 -7
  9. package/dist/copyFonts.js +14 -13
  10. package/dist/copyFonts.min.js +1 -1
  11. package/dist/default.js +16 -15
  12. package/dist/default.min.js +1 -1
  13. package/dist/dist.js +7 -7
  14. package/dist/distMinify.js +14 -13
  15. package/dist/distMinify.min.js +1 -1
  16. package/dist/images.js +7 -7
  17. package/dist/partials/addToReadme.js +3 -2
  18. package/dist/partials/beginWatcher.js +13 -12
  19. package/dist/partials/clean.js +15 -14
  20. package/dist/partials/distFor.js +22 -21
  21. package/dist/partials/distForSrc.js +12 -11
  22. package/dist/partials/distSeries.js +20 -19
  23. package/dist/partials/imagesFor.js +2 -1
  24. package/dist/partials/loadPeer.js +70 -70
  25. package/dist/partials/neostandardLint.js +163 -0
  26. package/dist/partials/readmeTemplate.js +15 -14
  27. package/dist/partials/runOnChange.js +29 -28
  28. package/dist/partials/sassFor.js +29 -28
  29. package/dist/partials/tsFor.js +2 -1
  30. package/dist/partials/typeDocsFor.js +2 -1
  31. package/dist/partials.js +136 -136
  32. package/dist/partials.min.js +1 -1
  33. package/dist/sass.js +7 -7
  34. package/dist/sourceLint.js +35 -0
  35. package/dist/sourceLint.min.js +1 -0
  36. package/dist/test-helpers/neostandardLintWithRealNeostandard.js +50 -0
  37. package/dist/test-helpers/setUp.js +2 -1
  38. package/dist/testFull.js +21 -20
  39. package/dist/testFull.min.js +1 -1
  40. package/dist/testHelpers.js +11 -10
  41. package/dist/testHelpers.min.js +1 -1
  42. package/dist/testQuick.js +23 -22
  43. package/dist/testQuick.min.js +1 -1
  44. package/dist/typeDocs.js +9 -9
  45. package/dist/typeScript.js +6 -6
  46. package/dist/utilities/convertMjsFilesForDocs.js +36 -36
  47. package/dist/utilities/dotNotate.js +48 -46
  48. package/dist/utilities/esmNamedExportsToCjs.js +18 -18
  49. package/dist/utilities/getBundleConfigs.js +3 -2
  50. package/dist/watchFull.js +7 -7
  51. package/dist/watchTest.js +17 -16
  52. package/dist/watchTest.min.js +1 -1
  53. package/functions/build.mjs +9 -8
  54. package/functions/build.test.mjs +18 -25
  55. package/functions/bundle.mjs +2 -2
  56. package/functions/partials/addToReadme.mjs +1 -1
  57. package/functions/partials/neostandardLint.mjs +130 -0
  58. package/functions/partials/neostandardLint.test.mjs +117 -0
  59. package/functions/partials.mjs +1 -1
  60. package/functions/sourceLint.mjs +24 -0
  61. package/functions/sourceLint.test.mjs +97 -0
  62. package/functions/test-helpers/neostandardLintWithRealNeostandard.mjs +40 -0
  63. package/functions/utilities/dotNotate.mjs +3 -1
  64. package/functions/utilities/dotNotate.test.mjs +34 -0
  65. package/functions/utilities/getBundleConfigs.mjs +1 -1
  66. package/gulp.config.mjs +14 -0
  67. package/gulpfile.base.js +2 -4
  68. package/gulpfile.base.mjs +1 -2
  69. package/package.json +7 -6
  70. package/dist/bundleLint.js +0 -28
  71. package/dist/bundleLint.min.js +0 -1
  72. package/dist/distLint.js +0 -20
  73. package/dist/distLint.min.js +0 -1
  74. package/dist/partials/standardLint.js +0 -94
  75. package/dist/test-helpers/standardLintWithRealStandard.js +0 -28
  76. package/functions/bundleLint.mjs +0 -18
  77. package/functions/bundleLint.test.mjs +0 -85
  78. package/functions/distLint.mjs +0 -12
  79. package/functions/distLint.test.mjs +0 -62
  80. package/functions/partials/standardLint.mjs +0 -78
  81. package/functions/partials/standardLint.test.mjs +0 -99
  82. package/functions/test-helpers/standardLintWithRealStandard.mjs +0 -21
package/gulp.config.mjs CHANGED
@@ -96,6 +96,16 @@ import { fileExists } from 'test-filesystem'
96
96
  * @property {StringSetting} from - Path to search for images.
97
97
  * @property {StringSetting} to - Path to output images.
98
98
  */
99
+ /**
100
+ * Configurations for linting (see {@link module:partials.neostandardLint}).
101
+ * @typedef {Object<string, Setting>} module:gulpConfig~LintConfig
102
+ * @property {Object<string, *>} rules - ESLint rule overrides layered on top of neostandard's own config, scoped
103
+ * to the same files neostandard itself lints. For a rule that is wrong for your project specifically (for example
104
+ * a test fixture that deliberately contains text neostandard mistakes for a real syntax problem), rather than
105
+ * something to fix in your code. Empty by default: a project that never sets this gets exactly neostandard's own
106
+ * rules, unchanged. Keyed and valued exactly as ESLint's own `rules` object - see
107
+ * https://eslint.org/docs/latest/use/configure/rules.
108
+ */
99
109
  /**
100
110
  * Configurations to compile and generate the Readme file.
101
111
  * @typedef {Object<string, Setting>} module:gulpConfig~ReadmeConfig
@@ -153,6 +163,7 @@ import { fileExists } from 'test-filesystem'
153
163
  * @property {DocsConfig} docs - Generate the documentation of a TypeScript project configuration group.
154
164
  * @property {FontConfig} fonts - Fonts copy configuration group.
155
165
  * @property {ImageConfig} images - Minify and copy the images configuration.
166
+ * @property {LintConfig} lint - Linting configuration group.
156
167
  * @property {ReadmeConfig} readme - Build readme files configuration.
157
168
  * @property {StringSetting} rootPath - Base directory of the project.
158
169
  * @property {SassConfig} sass - Compile CSS from SASS configuration.
@@ -200,6 +211,9 @@ const setDefaults = {
200
211
  from: 'src/img/**/*.+(png|jpg|jpeg|gif|svg)',
201
212
  to: 'browser/img',
202
213
  },
214
+ lint: {
215
+ rules: {},
216
+ },
203
217
  readme: {
204
218
  file: 'README.md',
205
219
  from: 'src/**/!(*.test).js',
package/gulpfile.base.js CHANGED
@@ -8,18 +8,17 @@
8
8
 
9
9
  const build = require('./dist/build.js')
10
10
  const bundle = require('./dist/bundle.js')
11
- const bundleLint = require('./dist/bundleLint.js')
12
11
  const bundleMinify = require('./dist/bundleMinify.js')
13
12
  const compileReadme = require('./dist/compileReadme.js')
14
13
  const copyFonts = require('./dist/copyFonts.js')
15
14
  const defaultCmd = require('./dist/default.js')
16
15
  const dist = require('./dist/dist.js')
17
- const distLint = require('./dist/distLint.js')
18
16
  const distMinify = require('./dist/distMinify.js')
19
17
  const gulpConfig = require('./gulp.config.js')
20
18
  const images = require('./dist/images.js')
21
19
  const partials = require('./dist/partials.js')
22
20
  const sass = require('./dist/sass.js')
21
+ const sourceLint = require('./dist/sourceLint.js')
23
22
  const testFull = require('./dist/testFull.js')
24
23
  const testHelpers = require('./dist/testHelpers.js')
25
24
  const testQuick = require('./dist/testQuick.js')
@@ -31,19 +30,18 @@ const watchTest = require('./dist/watchTest.js')
31
30
  module.exports = {
32
31
  build,
33
32
  bundle,
34
- bundleLint,
35
33
  bundleMinify,
36
34
  copyFonts,
37
35
  defaultCmd,
38
36
  docs: typeDocs,
39
37
  dist,
40
- distLint,
41
38
  distMinify,
42
39
  gulpConfig,
43
40
  images,
44
41
  partials,
45
42
  readme: compileReadme,
46
43
  sass,
44
+ sourceLint,
47
45
  testFull,
48
46
  testHelpers,
49
47
  testQuick,
package/gulpfile.base.mjs CHANGED
@@ -7,18 +7,17 @@
7
7
  */
8
8
  export { build } from './functions/build.mjs'
9
9
  export { bundle } from './functions/bundle.mjs'
10
- export { bundleLint } from './functions/bundleLint.mjs'
11
10
  export { bundleMinify } from './functions/bundleMinify.mjs'
12
11
  export { compileReadme as readme } from './functions/compileReadme.mjs'
13
12
  export { copyFonts } from './functions/copyFonts.mjs'
14
13
  export { defaultCmd } from './functions/default.mjs'
15
14
  export { dist } from './functions/dist.mjs'
16
- export { distLint } from './functions/distLint.mjs'
17
15
  export { distMinify } from './functions/distMinify.mjs'
18
16
  export * as gulpConfig from './gulp.config.mjs'
19
17
  export { images } from './functions/images.mjs'
20
18
  export * as partials from './functions/partials.mjs'
21
19
  export { sass } from './functions/sass.mjs'
20
+ export { sourceLint } from './functions/sourceLint.mjs'
22
21
  export { testFull } from './functions/testFull.mjs'
23
22
  export * as testHelpers from './functions/testHelpers.mjs'
24
23
  export { testQuick } from './functions/testQuick.mjs'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-build-tools",
3
- "version": "5.7.0",
3
+ "version": "6.1.0",
4
4
  "description": "Standardised build process with gulp.",
5
5
  "main": "gulpfile.base.js",
6
6
  "exports": {
@@ -50,12 +50,13 @@
50
50
  "@babel/plugin-transform-modules-commonjs": "^7.29.7",
51
51
  "@babel/preset-env": "^7.29.7",
52
52
  "@babel/preset-typescript": "^7.29.7",
53
- "@babel/runtime-corejs3": "^8.0.6",
53
+ "@babel/runtime-corejs3": "^8.0.7",
54
54
  "autoprefixer": "^10.6.1",
55
55
  "babel-jest": "^30.5.2",
56
56
  "browserify": "^17.0.1",
57
57
  "core-js": "^3.50.0",
58
58
  "cssnano": "^6.1.2",
59
+ "eslint": "^10.12.0",
59
60
  "glob": "^13.0.6",
60
61
  "gulp": "^5.0.1",
61
62
  "gulp-babel": "^8.1.0",
@@ -69,11 +70,11 @@
69
70
  "jest-environment-jsdom": "^30.5.2",
70
71
  "jsdoc-to-markdown": "^9.1.3",
71
72
  "merge-stream": "^2.0.0",
72
- "postcss": "^8.5.28",
73
+ "neostandard": "^0.14.1",
74
+ "postcss": "^8.5.30",
73
75
  "regenerator-runtime": "^0.14.1",
74
- "sass": "^1.105.0",
75
- "standard": "^17.1.2",
76
- "test-filesystem": "^1.5.1",
76
+ "sass": "^1.105.1",
77
+ "test-filesystem": "^2.0.0",
77
78
  "through2": "^4.0.2",
78
79
  "vinyl-source-stream": "^2.0.0"
79
80
  },
@@ -1,28 +0,0 @@
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.bundleLint = void 0
8
- require('core-js/modules/esnext.iterator.constructor.js')
9
- require('core-js/modules/esnext.iterator.map.js')
10
- const _gulp = require('gulp')
11
- const gulpConfig = _interopRequireWildcard(require('../gulp.config.js'))
12
- const _standardLint = require('./partials/standardLint.js')
13
- const _getBundleConfigs = require('./utilities/getBundleConfigs.js')
14
- 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) }
15
- /**
16
- * Applies Standard code style linting to every bundled file (the primary bundle, plus any
17
- * additional ones from browser.bundles). The lint step itself never varies per bundle, so this is
18
- * one shared src()/dest() pipeline fed every bundle's filename at once, rather than one pipeline
19
- * per bundle - gulp's src()/dest() both accept an array of paths natively.
20
- * @memberOf module:js-build-tools
21
- * @returns {stream.Stream}
22
- */
23
- const bundleLint = () => (0, _gulp.src)((0, _getBundleConfigs.getBundleConfigs)().map(({
24
- name
25
- }) => `${gulpConfig.get('browser.to')}/${name}.js`)).pipe((0, _standardLint.standardLint)({
26
- fix: true
27
- })).pipe((0, _gulp.dest)(gulpConfig.get('browser.to')))
28
- exports.bundleLint = bundleLint
@@ -1 +0,0 @@
1
- "use strict";require("core-js/modules/esnext.weak-map.delete-all.js"),Object.defineProperty(exports,"__esModule",{value:!0}),exports.bundleLint=void 0,require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.map.js");var _gulp=require("gulp"),gulpConfig=_interopRequireWildcard(require("../gulp.config.js")),_standardLint=require("./partials/standardLint.js"),_getBundleConfigs=require("./utilities/getBundleConfigs.js");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 i,o,u={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return u;if(i=t?n:r){if(i.has(e))return i.get(e);i.set(e,u)}for(const t in e)"default"!==t&&{}.hasOwnProperty.call(e,t)&&((o=(i=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(o.get||o.set)?i(u,t,o):u[t]=e[t]);return u})(e,t)}const bundleLint=()=>(0,_gulp.src)((0,_getBundleConfigs.getBundleConfigs)().map(({name:e})=>`${gulpConfig.get("browser.to")}/${e}.js`)).pipe((0,_standardLint.standardLint)({fix:!0})).pipe((0,_gulp.dest)(gulpConfig.get("browser.to")));exports.bundleLint=bundleLint;
package/dist/distLint.js DELETED
@@ -1,20 +0,0 @@
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.distLint = void 0
8
- const gulpConfig = _interopRequireWildcard(require('../gulp.config.js'))
9
- const _gulp = require('gulp')
10
- const _standardLint = require('./partials/standardLint.js')
11
- 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) }
12
- /**
13
- * Applies Standard code style linting to distribution files.
14
- * @memberOf module:js-build-tools
15
- * @returns {*}
16
- */
17
- const distLint = () => (0, _gulp.src)(gulpConfig.get('browser.from')).pipe((0, _standardLint.standardLint)({
18
- fix: true
19
- })).pipe((0, _gulp.dest)(gulpConfig.get('dist.to')))
20
- exports.distLint = distLint
@@ -1 +0,0 @@
1
- "use strict";require("core-js/modules/esnext.weak-map.delete-all.js"),Object.defineProperty(exports,"__esModule",{value:!0}),exports.distLint=void 0;var gulpConfig=_interopRequireWildcard(require("../gulp.config.js")),_gulp=require("gulp"),_standardLint=require("./partials/standardLint.js");function _interopRequireWildcard(e,t){if("function"==typeof WeakMap)var r=new WeakMap,i=new WeakMap;return(_interopRequireWildcard=function(e,t){if(!t&&e&&e.__esModule)return e;var n,o,s={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return s;if(n=t?i:r){if(n.has(e))return n.get(e);n.set(e,s)}for(const t in e)"default"!==t&&{}.hasOwnProperty.call(e,t)&&((o=(n=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(o.get||o.set)?n(s,t,o):s[t]=e[t]);return s})(e,t)}const distLint=()=>(0,_gulp.src)(gulpConfig.get("browser.from")).pipe((0,_standardLint.standardLint)({fix:!0})).pipe((0,_gulp.dest)(gulpConfig.get("dist.to")));exports.distLint=distLint;
@@ -1,94 +0,0 @@
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
-
16
- /**
17
- * Print a file's lint messages, if it has any.
18
- * @memberOf module:partials
19
- * @param {import('vinyl')} file
20
- * @param {{messages: Array<{line: number, column: number, message: string}>, errorCount: number, warningCount: number}} result
21
- * @returns {undefined}
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
-
36
- /**
37
- * Lint every file streaming through with JavaScript Standard Style and, unless `fix` is false, apply the automatic
38
- * fixes to the file's contents so a following `dest()` writes the fixed version. Remaining problems are printed
39
- * along with a summary once the stream ends; they never fail the build.
40
- *
41
- * Project-level Standard configuration (the `standard` field in package.json: ignore, env, globals, ...) is honored
42
- * because the file's own path and cwd are handed to Standard.
43
- * @memberOf module:partials
44
- * @param {Object} [options={}]
45
- * @param {boolean} [options.fix=true] - Apply Standard's automatic fixes to the file contents.
46
- * @param {function(): Promise<{lintText: Function}>} [loadStandard] - Resolves the `standard` module. Real callers
47
- * should never need to pass this - it exists so tests can supply a stand-in, since this project's
48
- * CommonJS-transform-based Jest setup cannot execute a real dynamic import() of an ES module.
49
- * @returns {import('stream').Transform}
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
- };
94
- exports.standardLint = standardLint;
@@ -1,28 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.standardLint = exports.loadStandardViaSubprocess = void 0;
7
- require("core-js/modules/es.json.stringify.js");
8
- var _nodeChild_process = require("node:child_process");
9
- // Jest's CommonJS transform cannot load `standard` (ESM-only) or run a real dynamic import(), so tests that need
10
- // genuine Standard behavior run the actual `standard` package in a plain Node subprocess instead of faking it.
11
- const script = 'import { readFileSync } from \'node:fs\'\n' + 'import standard from \'standard\'\n' + 'const { text, options } = JSON.parse(readFileSync(0, \'utf8\'))\n' + 'process.stdout.write(JSON.stringify(await standard.lintText(text, options)))\n';
12
- const loadStandardViaSubprocess = () => Promise.resolve({
13
- lintText: (text, options) => Promise.resolve().then(() => JSON.parse((0, _nodeChild_process.execFileSync)(process.execPath, ['--input-type=module', '--eval', script], {
14
- input: JSON.stringify({
15
- text,
16
- options
17
- }),
18
- encoding: 'utf8',
19
- cwd: process.cwd(),
20
- maxBuffer: 256 * 1024 * 1024
21
- })))
22
- });
23
- exports.loadStandardViaSubprocess = loadStandardViaSubprocess;
24
- const actual = jest.requireActual('../partials/standardLint.js');
25
-
26
- // Drop-in replacement for the partial module (see jest.mock in the lint/build tests): same API, real Standard.
27
- const standardLint = options => actual.standardLint(options, loadStandardViaSubprocess);
28
- exports.standardLint = standardLint;
@@ -1,18 +0,0 @@
1
- import { dest, src } from 'gulp'
2
- import * as gulpConfig from '../gulp.config.mjs'
3
- import { standardLint } from './partials/standardLint.mjs'
4
- import { getBundleConfigs } from './utilities/getBundleConfigs.mjs'
5
-
6
- /**
7
- * Applies Standard code style linting to every bundled file (the primary bundle, plus any
8
- * additional ones from browser.bundles). The lint step itself never varies per bundle, so this is
9
- * one shared src()/dest() pipeline fed every bundle's filename at once, rather than one pipeline
10
- * per bundle - gulp's src()/dest() both accept an array of paths natively.
11
- * @memberOf module:js-build-tools
12
- * @returns {stream.Stream}
13
- */
14
- export const bundleLint = () => src(
15
- getBundleConfigs().map(({ name }) => `${gulpConfig.get('browser.to')}/${name}.js`)
16
- )
17
- .pipe(standardLint({ fix: true }))
18
- .pipe(dest(gulpConfig.get('browser.to')))
@@ -1,85 +0,0 @@
1
- import fs from 'fs'
2
- import * as setUp from './test-helpers/setUp.mjs'
3
- import { bundleLint } from './bundleLint.mjs'
4
- import { countMatches } from 'test-filesystem'
5
-
6
- // Run the real Standard (in a subprocess) - Jest's CommonJS transform can't load the ESM-only package itself.
7
- jest.mock('./partials/standardLint.mjs', () => require('./test-helpers/standardLintWithRealStandard.mjs'))
8
-
9
- setUp.setDefaults('test-bundle-lint')
10
- const gulpConfig = setUp.gulpConfig
11
-
12
- const lintableContents = 'const gulpConfig = require("../gulp.config.js");\n' +
13
- 'const { dest, src } = require("gulp");\n' +
14
- 'const standard = require("gulp-standard");\n' +
15
- '\n' +
16
- '/**\n' +
17
- ' * Applies Standard code style linting to distribution files.\n' +
18
- ' * @returns {*}\n' +
19
- ' */\n' +
20
- 'const bundleLint = () => src(`${gulpConfig.get(\"browserPath\")}/${gulpConfig.get(\"browserName\")}.js`)\n' +
21
- ' .pipe(standard({ fix: true }))\n' +
22
- ' .pipe(standard.reporter("default", {\n' +
23
- ' fix: true,\n' +
24
- ' quiet: true\n' +
25
- ' }))\n' +
26
- ' .pipe(dest(gulpConfig.get("browserPath")));\n' +
27
- '\n' +
28
- 'module.exports = bundleLint;'
29
-
30
- beforeEach(
31
- () => setUp.beforeEach()
32
- .then(
33
- async () => {
34
- const browserPath = gulpConfig.get('browser.to')
35
- const browserName = gulpConfig.get('browser.name')
36
- await fs.mkdirSync(browserPath)
37
- return fs.writeFileSync(`${browserPath}/${browserName}.js`, lintableContents)
38
- }
39
- )
40
- )
41
-
42
- afterEach(setUp.afterEach)
43
-
44
- describe('bundleLint', () => {
45
- test('copies the src directory and babelifies it into the dist directory', done => {
46
- const browserPath = gulpConfig.get('browser.to')
47
- const browserName = gulpConfig.get('browser.name')
48
- const fullPath = `${browserPath}/${browserName}.js`
49
- const oldContents = fs.readFileSync(fullPath).toString()
50
- expect.assertions(4)
51
- expect(countMatches(oldContents, '"')).toEqual(14)
52
- expect(countMatches(oldContents, ';')).toEqual(5)
53
- bundleLint()
54
- .on('finish', () => {
55
- const lintedContents = fs.readFileSync(fullPath).toString()
56
- expect(countMatches(lintedContents, '"')).toEqual(0)
57
- expect(countMatches(lintedContents, ';')).toEqual(0)
58
- done()
59
- })
60
- .on('error', error => {
61
- console.error('Encountered error', error)
62
- done()
63
- })
64
- }, 10000)
65
-
66
- test('lints every additional bundle too, not just the primary one', done => {
67
- const browserPath = gulpConfig.get('browser.to')
68
- const renderOnlyFile = `${browserPath}/renderOnly.js`
69
- fs.writeFileSync(renderOnlyFile, lintableContents)
70
- gulpConfig.set('browser.bundles', [{ name: 'renderOnly' }])
71
- expect.assertions(2)
72
- bundleLint()
73
- .on('finish', () => {
74
- const lintedContents = fs.readFileSync(renderOnlyFile).toString()
75
- expect(countMatches(lintedContents, '"')).toEqual(0)
76
- expect(countMatches(lintedContents, ';')).toEqual(0)
77
- gulpConfig.set('browser.bundles', [])
78
- done()
79
- })
80
- .on('error', error => {
81
- console.error('Encountered error', error)
82
- done(error)
83
- })
84
- }, 10000)
85
- })
@@ -1,12 +0,0 @@
1
- import * as gulpConfig from '../gulp.config.mjs'
2
- import { dest, src } from 'gulp'
3
- import { standardLint } from './partials/standardLint.mjs'
4
-
5
- /**
6
- * Applies Standard code style linting to distribution files.
7
- * @memberOf module:js-build-tools
8
- * @returns {*}
9
- */
10
- export const distLint = () => src(gulpConfig.get('browser.from'))
11
- .pipe(standardLint({ fix: true }))
12
- .pipe(dest(gulpConfig.get('dist.to')))
@@ -1,62 +0,0 @@
1
- import fs from 'fs'
2
- import * as setUp from './test-helpers/setUp.mjs'
3
- import { distLint } from './distLint.mjs'
4
- import { countMatches } from 'test-filesystem'
5
-
6
- // Run the real Standard (in a subprocess) - Jest's CommonJS transform can't load the ESM-only package itself.
7
- jest.mock('./partials/standardLint.mjs', () => require('./test-helpers/standardLintWithRealStandard.mjs'))
8
-
9
- setUp.setDefaults('test-dist-lint')
10
- const gulpConfig = setUp.gulpConfig
11
-
12
- const lintableContents = 'const gulpConfig = require("../gulp.config.js");\n' +
13
- 'const { dest, src } = require("gulp");\n' +
14
- 'const standard = require("gulp-standard");\n' +
15
- '\n' +
16
- '/**\n' +
17
- ' * Applies Standard code style linting to distribution files.\n' +
18
- ' * @returns {*}\n' +
19
- ' */\n' +
20
- 'const distLint = () => src(gulpConfig.get("distSearch"))\n' +
21
- ' .pipe(standard({ fix: true }))\n' +
22
- ' .pipe(standard.reporter("default", {\n' +
23
- ' fix: true,\n' +
24
- ' quiet: true\n' +
25
- ' }))\n' +
26
- ' .pipe(dest(gulpConfig.get("distPath")));\n' +
27
- '\n' +
28
- 'module.exports = distLint;'
29
-
30
- beforeEach(
31
- () => setUp.beforeEach()
32
- .then(
33
- async () => {
34
- const distPath = gulpConfig.get('dist.to')
35
- await fs.mkdirSync(distPath)
36
- return fs.writeFileSync(`${distPath}/distLint.js`, lintableContents)
37
- }
38
- )
39
- )
40
-
41
- afterEach(setUp.afterEach)
42
-
43
- describe('distLint', () => {
44
- test('copies the src directory and babelifies it into the dist directory', done => {
45
- const distPath = gulpConfig.get('dist.to')
46
- const oldContents = fs.readFileSync(`${distPath}/distLint.js`).toString()
47
- expect.assertions(4)
48
- expect(countMatches(oldContents, '"')).toEqual(12)
49
- expect(countMatches(oldContents, ';')).toEqual(5)
50
- distLint()
51
- .on('finish', () => {
52
- const lintedContents = fs.readFileSync(`${distPath}/distLint.js`).toString()
53
- expect(countMatches(lintedContents, '"')).toEqual(0)
54
- expect(countMatches(lintedContents, ';')).toEqual(0)
55
- done()
56
- })
57
- .on('error', error => {
58
- console.error('Encountered error', error)
59
- done()
60
- })
61
- }, 10000)
62
- })
@@ -1,78 +0,0 @@
1
- import path from 'node:path'
2
- import through from 'through2'
3
- import { importModule } from './loadPeer.mjs'
4
-
5
- // `standard` (17+) ships ESM-only, see importModule for how it is imported.
6
- const importStandard = () => importModule('standard')
7
-
8
- /**
9
- * Print a file's lint messages, if it has any.
10
- * @memberOf module:partials
11
- * @param {import('vinyl')} file
12
- * @param {{messages: Array<{line: number, column: number, message: string}>, errorCount: number, warningCount: number}} result
13
- * @returns {undefined}
14
- */
15
- const printFileReport = (file, result) => {
16
- if (!result.messages.length) {
17
- return
18
- }
19
- console.log(path.relative(file.cwd, file.path))
20
- result.messages.forEach(({ line, column, message }) => console.log(`line ${line}:${column}\t${message}`))
21
- console.log(`✖ ${result.errorCount} error\t⚠ ${result.warningCount} warning\n`)
22
- }
23
-
24
- /**
25
- * Lint every file streaming through with JavaScript Standard Style and, unless `fix` is false, apply the automatic
26
- * fixes to the file's contents so a following `dest()` writes the fixed version. Remaining problems are printed
27
- * along with a summary once the stream ends; they never fail the build.
28
- *
29
- * Project-level Standard configuration (the `standard` field in package.json: ignore, env, globals, ...) is honored
30
- * because the file's own path and cwd are handed to Standard.
31
- * @memberOf module:partials
32
- * @param {Object} [options={}]
33
- * @param {boolean} [options.fix=true] - Apply Standard's automatic fixes to the file contents.
34
- * @param {function(): Promise<{lintText: Function}>} [loadStandard] - Resolves the `standard` module. Real callers
35
- * should never need to pass this - it exists so tests can supply a stand-in, since this project's
36
- * CommonJS-transform-based Jest setup cannot execute a real dynamic import() of an ES module.
37
- * @returns {import('stream').Transform}
38
- */
39
- export const standardLint = (
40
- { fix = true } = {},
41
- loadStandard = () => importStandard().then(({ default: standard }) => standard)
42
- ) => {
43
- const totals = { errors: 0, warnings: 0 }
44
- return through.obj(
45
- function (file, enc, callback) {
46
- if (file.isNull()) {
47
- callback(null, file)
48
- return
49
- }
50
- if (file.isStream()) {
51
- callback(new Error('standardLint: streaming file contents are not supported.'))
52
- return
53
- }
54
- loadStandard()
55
- .then(standard => standard.lintText(file.contents.toString(), { filename: file.path, cwd: file.cwd, fix }))
56
- .then(results => {
57
- // No result at all means the file is ignored by the project's Standard configuration.
58
- const [result] = results
59
- if (result) {
60
- if (typeof result.output === 'string') {
61
- file.contents = Buffer.from(result.output)
62
- }
63
- totals.errors += result.errorCount
64
- totals.warnings += result.warningCount
65
- printFileReport(file, result)
66
- }
67
- callback(null, file)
68
- }, callback)
69
- },
70
- function (callback) {
71
- console.log('Standard linter results')
72
- console.log('======================================')
73
- console.log(`✖ Errors total: ${totals.errors}`)
74
- console.log(`⚠ Warnings total: ${totals.warnings}\n`)
75
- callback()
76
- }
77
- )
78
- }