js-build-tools 6.6.0 → 6.8.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 (173) hide show
  1. package/LICENSE +674 -674
  2. package/README.md +768 -701
  3. package/babel.config.js +28 -28
  4. package/dist/build.js +75 -75
  5. package/dist/bundle.js +19 -19
  6. package/dist/bundleMinify.js +7 -7
  7. package/dist/compileReadme.js +4 -4
  8. package/dist/copyFiles.js +17 -17
  9. package/dist/copyFonts.js +4 -4
  10. package/dist/default.js +5 -5
  11. package/dist/dist.js +4 -4
  12. package/dist/distMinify.js +4 -4
  13. package/dist/docs.js +7 -7
  14. package/dist/images.js +4 -4
  15. package/dist/jsdocDocs.js +6 -6
  16. package/dist/lint.js +16 -16
  17. package/dist/partials/addToReadme.js +9 -9
  18. package/dist/partials/beginWatcher.js +4 -4
  19. package/dist/partials/cacheFiles.js +121 -0
  20. package/dist/partials/clean.js +5 -5
  21. package/dist/partials/copyFor.js +9 -9
  22. package/dist/partials/distFor.js +6 -6
  23. package/dist/partials/distForSrc.js +5 -5
  24. package/dist/partials/distSeries.js +7 -7
  25. package/dist/partials/imagesFor.js +155 -93
  26. package/dist/partials/jsdocDocsFor.js +64 -51
  27. package/dist/partials/lintSource.js +51 -51
  28. package/dist/partials/loadPeer.js +99 -99
  29. package/dist/partials/loadPlaywright.js +14 -14
  30. package/dist/partials/minifyFor.js +20 -20
  31. package/dist/partials/neostandardLint.js +175 -175
  32. package/dist/partials/readmeTemplate.js +4 -4
  33. package/dist/partials/removeDirectory.js +11 -11
  34. package/dist/partials/resolveDocsMethod.js +6 -6
  35. package/dist/partials/runOnChange.js +31 -31
  36. package/dist/partials/sassFor.js +6 -6
  37. package/dist/partials/serveStatic.js +9 -9
  38. package/dist/partials/tsFor.js +32 -32
  39. package/dist/partials/typeDocsFor.js +264 -264
  40. package/dist/partials.js +183 -176
  41. package/dist/partials.min.js +1 -1
  42. package/dist/sourceLint.js +18 -18
  43. package/dist/test-helpers/setUp.js +6 -4
  44. package/dist/testFull.js +5 -5
  45. package/dist/testQuick.js +5 -5
  46. package/dist/typeDocs.js +5 -5
  47. package/dist/typeScript.js +4 -4
  48. package/dist/utilities/convertMjsFilesForDocs.js +12 -12
  49. package/dist/utilities/dotGet.js +54 -54
  50. package/dist/utilities/dotNotate.js +79 -79
  51. package/dist/utilities/dotSet.js +45 -45
  52. package/dist/utilities/esmNamedExportsToCjs.js +15 -15
  53. package/dist/utilities/getBundleConfigs.js +9 -9
  54. package/dist/utilities/isObject.js +6 -6
  55. package/dist/utilities/strAfter.js +7 -7
  56. package/dist/utilities/strBefore.js +7 -7
  57. package/dist/watchFull.js +4 -4
  58. package/dist/watchTest.js +4 -4
  59. package/functions/build.mjs +72 -72
  60. package/functions/build.test.mjs +760 -759
  61. package/functions/bundle.mjs +44 -44
  62. package/functions/bundle.test.mjs +219 -219
  63. package/functions/bundleMinify.mjs +16 -16
  64. package/functions/bundleMinify.test.mjs +37 -37
  65. package/functions/compileReadme.mjs +9 -9
  66. package/functions/compileReadme.test.mjs +18 -18
  67. package/functions/copyFiles.mjs +32 -32
  68. package/functions/copyFiles.test.mjs +78 -78
  69. package/functions/copyFonts.mjs +9 -9
  70. package/functions/copyFonts.test.mjs +32 -32
  71. package/functions/default.mjs +12 -12
  72. package/functions/default.test.mjs +33 -33
  73. package/functions/dist.mjs +8 -8
  74. package/functions/dist.test.mjs +44 -44
  75. package/functions/distMinify.mjs +9 -9
  76. package/functions/distMinify.test.mjs +15 -15
  77. package/functions/docs.mjs +13 -13
  78. package/functions/docs.test.mjs +45 -45
  79. package/functions/gulpConfigEntries.test.mjs +23 -23
  80. package/functions/images.mjs +8 -8
  81. package/functions/images.test.mjs +140 -142
  82. package/functions/jsdocDocs.mjs +10 -10
  83. package/functions/jsdocEsmExports.test.mjs +24 -24
  84. package/functions/lint.mjs +9 -9
  85. package/functions/partials/addToReadme.mjs +25 -25
  86. package/functions/partials/addToReadme.test.mjs +34 -34
  87. package/functions/partials/beginWatcher.mjs +9 -9
  88. package/functions/partials/beginWatcher.test.mjs +19 -19
  89. package/functions/partials/cacheFiles.mjs +114 -0
  90. package/functions/partials/cacheFiles.test.mjs +151 -0
  91. package/functions/partials/clean.mjs +13 -13
  92. package/functions/partials/clean.test.mjs +22 -22
  93. package/functions/partials/copyFor.mjs +15 -15
  94. package/functions/partials/copyFor.test.mjs +53 -53
  95. package/functions/partials/distFor.mjs +22 -22
  96. package/functions/partials/distFor.test.mjs +195 -195
  97. package/functions/partials/distForSrc.mjs +11 -11
  98. package/functions/partials/distForSrc.test.mjs +18 -18
  99. package/functions/partials/distSeries.mjs +21 -21
  100. package/functions/partials/distSeries.test.mjs +34 -34
  101. package/functions/partials/imagesFor.mjs +147 -83
  102. package/functions/partials/imagesFor.test.mjs +311 -287
  103. package/functions/partials/jsdocDocsFor.mjs +163 -152
  104. package/functions/partials/jsdocDocsFor.test.mjs +182 -152
  105. package/functions/partials/lintSource.mjs +41 -41
  106. package/functions/partials/loadPeer.mjs +76 -76
  107. package/functions/partials/loadPeer.test.mjs +58 -58
  108. package/functions/partials/loadPlaywright.mjs +23 -23
  109. package/functions/partials/loadPlaywright.test.mjs +70 -70
  110. package/functions/partials/minifyFor.mjs +15 -15
  111. package/functions/partials/minifyFor.test.mjs +49 -49
  112. package/functions/partials/neostandardLint.mjs +142 -142
  113. package/functions/partials/neostandardLint.test.mjs +131 -131
  114. package/functions/partials/readmeTemplate.mjs +12 -12
  115. package/functions/partials/readmeTemplate.test.mjs +34 -34
  116. package/functions/partials/removeDirectory.mjs +34 -34
  117. package/functions/partials/removeDirectory.test.mjs +72 -72
  118. package/functions/partials/resolveDocsMethod.mjs +10 -10
  119. package/functions/partials/resolveDocsMethod.test.mjs +33 -33
  120. package/functions/partials/runOnChange.mjs +54 -54
  121. package/functions/partials/runOnChange.test.mjs +95 -95
  122. package/functions/partials/sassFor.mjs +25 -25
  123. package/functions/partials/sassFor.test.mjs +81 -81
  124. package/functions/partials/serveStatic.mjs +47 -47
  125. package/functions/partials/serveStatic.test.mjs +71 -71
  126. package/functions/partials/tsFor.mjs +92 -92
  127. package/functions/partials/tsFor.test.mjs +88 -88
  128. package/functions/partials/typeDocsFor.mjs +231 -231
  129. package/functions/partials/typeDocsFor.test.mjs +263 -263
  130. package/functions/partials.mjs +32 -31
  131. package/functions/partials.test.mjs +7 -7
  132. package/functions/sass.mjs +4 -4
  133. package/functions/sass.test.mjs +31 -31
  134. package/functions/sourceLint.mjs +13 -13
  135. package/functions/sourceLint.test.mjs +166 -166
  136. package/functions/test-helpers/neostandardLintWithRealNeostandard.mjs +40 -40
  137. package/functions/test-helpers/setUp.mjs +102 -100
  138. package/functions/test-helpers/setUp.test.mjs +19 -19
  139. package/functions/testFull.mjs +17 -17
  140. package/functions/testFull.test.mjs +17 -17
  141. package/functions/testHelpers.mjs +10 -10
  142. package/functions/testHelpers.test.mjs +7 -7
  143. package/functions/testQuick.mjs +17 -17
  144. package/functions/testQuick.test.mjs +17 -17
  145. package/functions/typeDocs.mjs +9 -9
  146. package/functions/typeDocs.test.mjs +11 -11
  147. package/functions/typeScript.mjs +8 -8
  148. package/functions/typeScript.test.mjs +11 -11
  149. package/functions/utilities/convertMjsFilesForDocs.mjs +34 -34
  150. package/functions/utilities/convertMjsFilesForDocs.test.mjs +58 -58
  151. package/functions/utilities/dotGet.mjs +49 -49
  152. package/functions/utilities/dotNotate.mjs +73 -73
  153. package/functions/utilities/dotNotate.test.mjs +41 -41
  154. package/functions/utilities/dotSet.mjs +40 -40
  155. package/functions/utilities/esmNamedExportsToCjs.mjs +30 -30
  156. package/functions/utilities/esmNamedExportsToCjs.test.mjs +47 -47
  157. package/functions/utilities/getBundleConfigs.mjs +30 -30
  158. package/functions/utilities/isObject.mjs +8 -8
  159. package/functions/utilities/strAfter.mjs +12 -12
  160. package/functions/utilities/strBefore.mjs +12 -12
  161. package/functions/watchFull.mjs +9 -9
  162. package/functions/watchFull.test.mjs +41 -41
  163. package/functions/watchTest.mjs +10 -10
  164. package/functions/watchTest.test.mjs +49 -49
  165. package/gulp.config.js +4 -4
  166. package/gulp.config.mjs +349 -340
  167. package/gulpfile.base.js +51 -51
  168. package/gulpfile.base.mjs +29 -29
  169. package/jsdoc.base.js +16 -16
  170. package/jsdoc.esmExports.js +17 -17
  171. package/package.json +146 -145
  172. package/dist/test-helpers/isolateGulpCache.js +0 -25
  173. package/functions/test-helpers/isolateGulpCache.mjs +0 -16
@@ -31,23 +31,23 @@ const escapeHtml = text => String(text).replace(/&/g, '&amp;').replace(/</g, '&l
31
31
  const jsdocInstallHint = 'Install it in your project with: npm install --save-dev jsdoc';
32
32
  const themeInstallHint = name => `Install it in your project with: npm install --save-dev ${name}`;
33
33
 
34
- /**
35
- * Resolve the installed directory of an optional peer dependency, from the project being built rather than from
36
- * this package. Deliberately not requirePeer/importPeer's own `require(name + '/package.json')` approach - that
37
- * breaks for any package whose own package.json restricts its exports map and does not expose that subpath
38
- * (clean-jsdoc-theme does; confirmed live, not assumed - resolving its own package.json throws
39
- * ERR_PACKAGE_PATH_NOT_EXPORTED in plain Node, and a differently-shaped MODULE_NOT_FOUND under Jest's own
40
- * resolver, which still is not "not installed" either way). Walking Node's own real module-lookup directories
41
- * (require.resolve.paths) and checking each on disk sidesteps the exports map entirely - this only ever reads
42
- * whether `<dir>/<name>/package.json` exists, never asks the module system to resolve a restricted subpath.
43
- * @memberOf module:partials
44
- * @param {string} name - The package name.
45
- * @param {Object} options
46
- * @param {string} options.task
47
- * @param {string} options.installHint
48
- * @param {string} [options.projectPath=process.cwd()]
49
- * @returns {string}
50
- * @throws {Error} With install instructions when the package is not installed.
34
+ /**
35
+ * Resolve the installed directory of an optional peer dependency, from the project being built rather than from
36
+ * this package. Deliberately not requirePeer/importPeer's own `require(name + '/package.json')` approach - that
37
+ * breaks for any package whose own package.json restricts its exports map and does not expose that subpath
38
+ * (clean-jsdoc-theme does; confirmed live, not assumed - resolving its own package.json throws
39
+ * ERR_PACKAGE_PATH_NOT_EXPORTED in plain Node, and a differently-shaped MODULE_NOT_FOUND under Jest's own
40
+ * resolver, which still is not "not installed" either way). Walking Node's own real module-lookup directories
41
+ * (require.resolve.paths) and checking each on disk sidesteps the exports map entirely - this only ever reads
42
+ * whether `<dir>/<name>/package.json` exists, never asks the module system to resolve a restricted subpath.
43
+ * @memberOf module:partials
44
+ * @param {string} name - The package name.
45
+ * @param {Object} options
46
+ * @param {string} options.task
47
+ * @param {string} options.installHint
48
+ * @param {string} [options.projectPath=process.cwd()]
49
+ * @returns {string}
50
+ * @throws {Error} With install instructions when the package is not installed.
51
51
  */
52
52
  const resolvePeerDir = (name, {
53
53
  task,
@@ -62,15 +62,15 @@ const resolvePeerDir = (name, {
62
62
  return found;
63
63
  };
64
64
 
65
- /**
66
- * Resolve jsdoc's own CLI entry point. jsdoc has no stable programmatic Node API for generating HTML docs (unlike
67
- * TypeDoc's Application.bootstrap()/convert()/generateDocs()) - gulp-jsdoc3, the established gulp wrapper, is
68
- * stale, and its own README admits jsdoc does not support piped input in the first place, a real anti-pattern for
69
- * this project's own gulp-stream conventions. Running its real CLI via child_process is the portable way in -
70
- * confirmed via `npm view jsdoc bin`, which reports "jsdoc.js" at the package root.
71
- * @memberOf module:partials
72
- * @param {string} [projectPath=process.cwd()]
73
- * @returns {string}
65
+ /**
66
+ * Resolve jsdoc's own CLI entry point. jsdoc has no stable programmatic Node API for generating HTML docs (unlike
67
+ * TypeDoc's Application.bootstrap()/convert()/generateDocs()) - gulp-jsdoc3, the established gulp wrapper, is
68
+ * stale, and its own README admits jsdoc does not support piped input in the first place, a real anti-pattern for
69
+ * this project's own gulp-stream conventions. Running its real CLI via child_process is the portable way in -
70
+ * confirmed via `npm view jsdoc bin`, which reports "jsdoc.js" at the package root.
71
+ * @memberOf module:partials
72
+ * @param {string} [projectPath=process.cwd()]
73
+ * @returns {string}
74
74
  */
75
75
  const resolveJsdocBin = (projectPath = process.cwd()) => _nodePath.default.join(resolvePeerDir('jsdoc', {
76
76
  task: 'docs',
@@ -78,14 +78,14 @@ const resolveJsdocBin = (projectPath = process.cwd()) => _nodePath.default.join(
78
78
  projectPath
79
79
  }), 'jsdoc.js');
80
80
 
81
- /**
82
- * Resolve a jsdoc theme package's own template directory, for jsdoc's own opts.template config key: the folder
83
- * holding its publish.js. That is the package root for a classic jsdoc template (clean-jsdoc-theme 4.x included),
84
- * but `dist` for a bundled one (clean-jsdoc-theme 5.x).
85
- * @memberOf module:partials
86
- * @param {string} name
87
- * @param {string} [projectPath=process.cwd()]
88
- * @returns {string}
81
+ /**
82
+ * Resolve a jsdoc theme package's own template directory, for jsdoc's own opts.template config key: the folder
83
+ * holding its publish.js. That is the package root for a classic jsdoc template (clean-jsdoc-theme 4.x included),
84
+ * but `dist` for a bundled one (clean-jsdoc-theme 5.x).
85
+ * @memberOf module:partials
86
+ * @param {string} name
87
+ * @param {string} [projectPath=process.cwd()]
88
+ * @returns {string}
89
89
  */
90
90
  exports.resolveJsdocBin = resolveJsdocBin;
91
91
  const resolveJsdocTheme = (name, projectPath = process.cwd()) => {
@@ -98,18 +98,18 @@ const resolveJsdocTheme = (name, projectPath = process.cwd()) => {
98
98
  return _nodeFs.default.existsSync(_nodePath.default.join(distDir, 'publish.js')) ? distDir : packageDir;
99
99
  };
100
100
 
101
- /**
102
- * Generate the HTML documentation of a plain-JavaScript project with jsdoc, using jsdoc.base.js's own shared
103
- * config (plugins, includePattern/excludePattern) as the starting point rather than a parallel one - the same
104
- * base a project's own .jsdoc.conf.js has always been able to extend, just with source.include and the output
105
- * options generated here instead of hand-maintained per project. Configure this with 'docs.from', 'docs.to',
106
- * 'docs.index', 'docs.theme' and 'docs.title'.
107
- * @memberOf module:partials
108
- * @param {string|Array<string>} [srcPath=gulpConfig.get('docs.from')] - The directory (or directories and files) holding
109
- * the JS source.
110
- * @param {string} [outPath=gulpConfig.get('docs.to')] - The directory the documentation is generated into (cleared first).
111
- * @param {function(string, Array<string>): Promise<Object>} [runJsdoc] - Runs the jsdoc CLI, tests can inject a stand-in.
112
- * @returns {Function} A gulp task, it accepts an optional callback and returns a promise.
101
+ /**
102
+ * Generate the HTML documentation of a plain-JavaScript project with jsdoc, using jsdoc.base.js's own shared
103
+ * config (plugins, includePattern/excludePattern) as the starting point rather than a parallel one - the same
104
+ * base a project's own .jsdoc.conf.js has always been able to extend, just with source.include and the output
105
+ * options generated here instead of hand-maintained per project. Configure this with 'docs.from', 'docs.to',
106
+ * 'docs.index', 'docs.theme' and 'docs.title'.
107
+ * @memberOf module:partials
108
+ * @param {string|Array<string>} [srcPath=gulpConfig.get('docs.from')] - The directory (or directories and files) holding
109
+ * the JS source.
110
+ * @param {string} [outPath=gulpConfig.get('docs.to')] - The directory the documentation is generated into (cleared first).
111
+ * @param {function(string, Array<string>): Promise<Object>} [runJsdoc] - Runs the jsdoc CLI, tests can inject a stand-in.
112
+ * @returns {Function} A gulp task, it accepts an optional callback and returns a promise.
113
113
  */
114
114
  exports.resolveJsdocTheme = resolveJsdocTheme;
115
115
  const jsdocDocsFor = (srcPath = gulpConfig.get('docs.from'), outPath = gulpConfig.get('docs.to'), runJsdoc = (bin, args) => execFileAsync(process.execPath, [bin, ...args])) => {
@@ -122,7 +122,15 @@ const jsdocDocsFor = (srcPath = gulpConfig.get('docs.from'), outPath = gulpConfi
122
122
  const themeDir = resolveJsdocTheme(theme);
123
123
  const indexFile = gulpConfig.get('docs.index');
124
124
  const title = gulpConfig.get('docs.title');
125
+ const basePath = gulpConfig.get('docs.basePath');
125
126
  await (0, _removeDirectory.removeDirectory)(outPath);
127
+ const workDir = _nodeFs.default.mkdtempSync(_nodePath.default.join(_nodeOs.default.tmpdir(), 'jsdocdocs-'));
128
+ // clean-jsdoc-theme 5.x writes no index.html at all without a front page, so fall back to one with the title
129
+ let readme = indexFile && _nodeFs.default.existsSync(indexFile) ? _nodePath.default.resolve(indexFile) : '';
130
+ if (!readme) {
131
+ readme = _nodePath.default.join(workDir, 'index.md');
132
+ _nodeFs.default.writeFileSync(readme, `# ${title || 'Documentation'}\n`);
133
+ }
126
134
  const config = {
127
135
  ..._jsdocBase.default,
128
136
  source: {
@@ -136,21 +144,26 @@ const jsdocDocsFor = (srcPath = gulpConfig.get('docs.from'), outPath = gulpConfi
136
144
  // quick-start example, which sets this explicitly, not assumed from jsdoc's own classic defaults.
137
145
  recurse: true,
138
146
  template: themeDir,
139
- // clean-jsdoc-theme's own options for the name in its header and the home page's <title> (otherwise "Home").
147
+ // clean-jsdoc-theme 4.x's own options for the name in its header and the home page's <title> (otherwise "Home").
140
148
  // The header is given as a link: a plain-text title links to the site root ("/"), while every page is in one
141
149
  // folder, so index.html is the home page wherever they are served. Both are printed unescaped by the theme.
150
+ // clean-jsdoc-theme 5.x reads its options from opts itself: the name in its header and <title>, and the path
151
+ // its root-absolute links start from (4.x reads only theme_opts).
152
+ ...(title ? {
153
+ siteName: title
154
+ } : {}),
155
+ ...(basePath ? {
156
+ basePath
157
+ } : {}),
142
158
  ...(title ? {
143
159
  theme_opts: {
144
160
  title: `<a href="index.html" class="sidebar-title sidebar-title-anchor">${escapeHtml(title)}</a>`,
145
161
  homepageTitle: escapeHtml(title)
146
162
  }
147
163
  } : {}),
148
- ...(indexFile && _nodeFs.default.existsSync(indexFile) ? {
149
- readme: _nodePath.default.resolve(indexFile)
150
- } : {})
164
+ readme
151
165
  }
152
166
  };
153
- const workDir = _nodeFs.default.mkdtempSync(_nodePath.default.join(_nodeOs.default.tmpdir(), 'jsdocdocs-'));
154
167
  try {
155
168
  const configPath = _nodePath.default.join(workDir, 'jsdoc.conf.json');
156
169
  _nodeFs.default.writeFileSync(configPath, JSON.stringify(config));
@@ -1,52 +1,52 @@
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.lintSource = void 0;
8
- var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
9
- var _gulp = require("gulp");
10
- var _neostandardLint = require("./neostandardLint.js");
11
- var _nodeStream = require("node:stream");
12
- var cache;
13
- function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
14
- /**
15
- * Lint the project's source (srcPath: .js, .mjs and .cjs, plus .ts when typescript.enabled) with neostandard and
16
- * write the automatic fixes back in place. Shared by the sourceLint (build) and lint (standalone) tasks.
17
- * @memberOf module:partials
18
- * @param {Object} [options={}]
19
- * @param {boolean} [options.failOnError=false] - Fail once linting finishes if any errors could not be fixed.
20
- * @returns {stream.Stream}
21
- */
22
- const lintSource = ({
23
- failOnError = false
24
- } = {}) => {
25
- const srcPath = gulpConfig.get('srcPath');
26
- const ts = gulpConfig.get('typescript.enabled');
27
- const patterns = [`${srcPath}/**/*.{js,mjs,cjs}`];
28
- if (ts) {
29
- patterns.push(`${srcPath}/**/*.ts`);
30
- }
31
- const linter = (0, _neostandardLint.neostandardLint)({
32
- fix: true,
33
- ts,
34
- rules: gulpConfig.get('lint.rules')
35
- });
36
- // Fail only once dest() has written every fixed file: gulp exits as soon as a task fails, so failing from the
37
- // linter itself (before dest() finished) could leave a file that dest() had opened, but not yet written, empty.
38
- // dest() passes each file on only after writing it, so this last step's flush runs after the final write. Files
39
- // are consumed here rather than passed on, so nothing downstream has to read them.
40
- const written = new _nodeStream.Transform({
41
- objectMode: true,
42
- transform: (file, enc, callback) => callback(),
43
- flush: callback => failOnError && linter.totals.errors ? callback(new Error(`neostandard found ${linter.totals.errors} lint error(s) that could not be fixed automatically.`)) : callback()
44
- });
45
- const saved = (0, _gulp.src)(patterns).pipe(linter).pipe((0, _gulp.dest)(srcPath));
46
- saved.pipe(written);
47
- // pipe() does not forward errors, and gulp only watches the returned stream, so pass any failure along.
48
- linter.on('error', error => written.destroy(error));
49
- saved.on('error', error => written.destroy(error));
50
- return written;
51
- };
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.lintSource = void 0;
8
+ var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
9
+ var _gulp = require("gulp");
10
+ var _neostandardLint = require("./neostandardLint.js");
11
+ var _nodeStream = require("node:stream");
12
+ var cache;
13
+ function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
14
+ /**
15
+ * Lint the project's source (srcPath: .js, .mjs and .cjs, plus .ts when typescript.enabled) with neostandard and
16
+ * write the automatic fixes back in place. Shared by the sourceLint (build) and lint (standalone) tasks.
17
+ * @memberOf module:partials
18
+ * @param {Object} [options={}]
19
+ * @param {boolean} [options.failOnError=false] - Fail once linting finishes if any errors could not be fixed.
20
+ * @returns {stream.Stream}
21
+ */
22
+ const lintSource = ({
23
+ failOnError = false
24
+ } = {}) => {
25
+ const srcPath = gulpConfig.get('srcPath');
26
+ const ts = gulpConfig.get('typescript.enabled');
27
+ const patterns = [`${srcPath}/**/*.{js,mjs,cjs}`];
28
+ if (ts) {
29
+ patterns.push(`${srcPath}/**/*.ts`);
30
+ }
31
+ const linter = (0, _neostandardLint.neostandardLint)({
32
+ fix: true,
33
+ ts,
34
+ rules: gulpConfig.get('lint.rules')
35
+ });
36
+ // Fail only once dest() has written every fixed file: gulp exits as soon as a task fails, so failing from the
37
+ // linter itself (before dest() finished) could leave a file that dest() had opened, but not yet written, empty.
38
+ // dest() passes each file on only after writing it, so this last step's flush runs after the final write. Files
39
+ // are consumed here rather than passed on, so nothing downstream has to read them.
40
+ const written = new _nodeStream.Transform({
41
+ objectMode: true,
42
+ transform: (file, enc, callback) => callback(),
43
+ flush: callback => failOnError && linter.totals.errors ? callback(new Error(`neostandard found ${linter.totals.errors} lint error(s) that could not be fixed automatically.`)) : callback()
44
+ });
45
+ const saved = (0, _gulp.src)(patterns).pipe(linter).pipe((0, _gulp.dest)(srcPath));
46
+ saved.pipe(written);
47
+ // pipe() does not forward errors, and gulp only watches the returned stream, so pass any failure along.
48
+ linter.on('error', error => written.destroy(error));
49
+ saved.on('error', error => written.destroy(error));
50
+ return written;
51
+ };
52
52
  exports.lintSource = lintSource;
@@ -1,100 +1,100 @@
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
- // eslint-disable-next-line no-new-func -- deliberate, see above
17
- const dynamicImport = new Function('specifier', 'return import(specifier)');
18
-
19
- /**
20
- * Import an ES module (or any module) with a real dynamic import(), whichever build (ESM or CommonJS) this runs from.
21
- * @memberOf module:partials
22
- * @param {string} specifier - The package name, or the URL of a file.
23
- * @returns {Promise<Object>} The module namespace.
24
- */
25
- const importModule = specifier => dynamicImport(specifier);
26
- exports.importModule = importModule;
27
- const isMissing = (error, name) => error.code === 'MODULE_NOT_FOUND' && error.message.includes(`'${name}'`);
28
- const notInstalled = (name, {
29
- task,
30
- installHint
31
- }) => new Error(`The ${task} task needs the optional peer dependency ${name}, which is not installed. ${installHint}`);
32
-
33
- /**
34
- * Load an optional peer dependency (one which is only needed once a task runs, so projects which never use that task
35
- * do not have to install it) with require(), from the project being built rather than from this package. When it is
36
- * missing the error explains how to install it.
37
- * @memberOf module:partials
38
- * @param {string} name - The package name.
39
- * @param {Object} options
40
- * @param {string} options.task - The task which needs the package, for the error message.
41
- * @param {string} options.installHint - How to install it, for the error message.
42
- * @param {string} [options.esmOnlyMessage] - The error message when the package turns out to be ESM-only (it cannot be require()d).
43
- * @param {string} [options.projectPath=process.cwd()] - The folder of the project (which has the package.json) being built.
44
- * @returns {*} Whatever the package exports.
45
- * @throws {Error} With install instructions when the package is not installed.
46
- */
47
- const requirePeer = (name, {
48
- task,
49
- installHint,
50
- esmOnlyMessage,
51
- projectPath = process.cwd()
52
- }) => {
53
- try {
54
- return (0, _nodeModule.createRequire)(_nodePath.default.join(projectPath, 'package.json'))(name);
55
- } catch (error) {
56
- if (isMissing(error, name)) {
57
- throw notInstalled(name, {
58
- task,
59
- installHint
60
- });
61
- }
62
- if (error.code === 'ERR_REQUIRE_ESM' && esmOnlyMessage) {
63
- throw new Error(esmOnlyMessage);
64
- }
65
- throw error;
66
- }
67
- };
68
-
69
- /**
70
- * Import an optional peer dependency which ships ESM-only, from the project being built. See {@link requirePeer}.
71
- * @memberOf module:partials
72
- * @param {string} name - The package name.
73
- * @param {Object} options
74
- * @param {string} options.task - The task which needs the package, for the error message.
75
- * @param {string} options.installHint - How to install it, for the error message.
76
- * @param {string} [options.projectPath=process.cwd()] - The folder of the project (which has the package.json) being built.
77
- * @returns {Promise<Object>} The module namespace.
78
- * @throws {Error} With install instructions when the package is not installed.
79
- */
80
- exports.requirePeer = requirePeer;
81
- const importPeer = async (name, {
82
- task,
83
- installHint,
84
- projectPath = process.cwd()
85
- }) => {
86
- let resolved;
87
- try {
88
- resolved = (0, _nodeModule.createRequire)(_nodePath.default.join(projectPath, 'package.json')).resolve(name);
89
- } catch (error) {
90
- if (isMissing(error, name)) {
91
- throw notInstalled(name, {
92
- task,
93
- installHint
94
- });
95
- }
96
- throw error;
97
- }
98
- return importModule((0, _nodeUrl.pathToFileURL)(resolved).href);
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
+ // eslint-disable-next-line no-new-func -- deliberate, see above
17
+ const dynamicImport = new Function('specifier', 'return import(specifier)');
18
+
19
+ /**
20
+ * Import an ES module (or any module) with a real dynamic import(), whichever build (ESM or CommonJS) this runs from.
21
+ * @memberOf module:partials
22
+ * @param {string} specifier - The package name, or the URL of a file.
23
+ * @returns {Promise<Object>} The module namespace.
24
+ */
25
+ const importModule = specifier => dynamicImport(specifier);
26
+ exports.importModule = importModule;
27
+ const isMissing = (error, name) => error.code === 'MODULE_NOT_FOUND' && error.message.includes(`'${name}'`);
28
+ const notInstalled = (name, {
29
+ task,
30
+ installHint
31
+ }) => new Error(`The ${task} task needs the optional peer dependency ${name}, which is not installed. ${installHint}`);
32
+
33
+ /**
34
+ * Load an optional peer dependency (one which is only needed once a task runs, so projects which never use that task
35
+ * do not have to install it) with require(), from the project being built rather than from this package. When it is
36
+ * missing the error explains how to install it.
37
+ * @memberOf module:partials
38
+ * @param {string} name - The package name.
39
+ * @param {Object} options
40
+ * @param {string} options.task - The task which needs the package, for the error message.
41
+ * @param {string} options.installHint - How to install it, for the error message.
42
+ * @param {string} [options.esmOnlyMessage] - The error message when the package turns out to be ESM-only (it cannot be require()d).
43
+ * @param {string} [options.projectPath=process.cwd()] - The folder of the project (which has the package.json) being built.
44
+ * @returns {*} Whatever the package exports.
45
+ * @throws {Error} With install instructions when the package is not installed.
46
+ */
47
+ const requirePeer = (name, {
48
+ task,
49
+ installHint,
50
+ esmOnlyMessage,
51
+ projectPath = process.cwd()
52
+ }) => {
53
+ try {
54
+ return (0, _nodeModule.createRequire)(_nodePath.default.join(projectPath, 'package.json'))(name);
55
+ } catch (error) {
56
+ if (isMissing(error, name)) {
57
+ throw notInstalled(name, {
58
+ task,
59
+ installHint
60
+ });
61
+ }
62
+ if (error.code === 'ERR_REQUIRE_ESM' && esmOnlyMessage) {
63
+ throw new Error(esmOnlyMessage);
64
+ }
65
+ throw error;
66
+ }
67
+ };
68
+
69
+ /**
70
+ * Import an optional peer dependency which ships ESM-only, from the project being built. See {@link requirePeer}.
71
+ * @memberOf module:partials
72
+ * @param {string} name - The package name.
73
+ * @param {Object} options
74
+ * @param {string} options.task - The task which needs the package, for the error message.
75
+ * @param {string} options.installHint - How to install it, for the error message.
76
+ * @param {string} [options.projectPath=process.cwd()] - The folder of the project (which has the package.json) being built.
77
+ * @returns {Promise<Object>} The module namespace.
78
+ * @throws {Error} With install instructions when the package is not installed.
79
+ */
80
+ exports.requirePeer = requirePeer;
81
+ const importPeer = async (name, {
82
+ task,
83
+ installHint,
84
+ projectPath = process.cwd()
85
+ }) => {
86
+ let resolved;
87
+ try {
88
+ resolved = (0, _nodeModule.createRequire)(_nodePath.default.join(projectPath, 'package.json')).resolve(name);
89
+ } catch (error) {
90
+ if (isMissing(error, name)) {
91
+ throw notInstalled(name, {
92
+ task,
93
+ installHint
94
+ });
95
+ }
96
+ throw error;
97
+ }
98
+ return importModule((0, _nodeUrl.pathToFileURL)(resolved).href);
99
+ };
100
100
  exports.importPeer = importPeer;
@@ -7,13 +7,13 @@ exports.loadPlaywright = exports.launchBrowser = void 0;
7
7
  var _loadPeer = require("./loadPeer.js");
8
8
  const installHint = 'Install it in your project with: npm install --save-dev playwright';
9
9
 
10
- /**
11
- * Find Playwright (headless-browser automation) of the project being built, an optional peer dependency only
12
- * needed by whatever actually drives a real browser - projects which never do never need it installed.
13
- * @memberOf module:partials
14
- * @param {string} [projectPath=process.cwd()] The folder of the project (which has the package.json) being built.
15
- * @returns {Object} The Playwright module.
16
- * @throws {Error} With install instructions when playwright is not installed.
10
+ /**
11
+ * Find Playwright (headless-browser automation) of the project being built, an optional peer dependency only
12
+ * needed by whatever actually drives a real browser - projects which never do never need it installed.
13
+ * @memberOf module:partials
14
+ * @param {string} [projectPath=process.cwd()] The folder of the project (which has the package.json) being built.
15
+ * @returns {Object} The Playwright module.
16
+ * @throws {Error} With install instructions when playwright is not installed.
17
17
  */
18
18
  const loadPlaywright = (projectPath = process.cwd()) => (0, _loadPeer.requirePeer)('playwright', {
19
19
  task: 'browser automation',
@@ -21,13 +21,13 @@ const loadPlaywright = (projectPath = process.cwd()) => (0, _loadPeer.requirePee
21
21
  projectPath
22
22
  });
23
23
 
24
- /**
25
- * Launch a real headless Chromium browser via Playwright. See {@link loadPlaywright}.
26
- * @memberOf module:partials
27
- * @param {Function} [load=loadPlaywright] Which Playwright to launch - swappable in tests.
28
- * @param {string} [projectPath=process.cwd()] The folder of the project (which has the package.json) being built.
29
- * @returns {Promise<Browser>} The running Playwright browser - close it yourself (browser.close()) once done with it.
30
- * @throws {Error} With install instructions when playwright is not installed.
24
+ /**
25
+ * Launch a real headless Chromium browser via Playwright. See {@link loadPlaywright}.
26
+ * @memberOf module:partials
27
+ * @param {Function} [load=loadPlaywright] Which Playwright to launch - swappable in tests.
28
+ * @param {string} [projectPath=process.cwd()] The folder of the project (which has the package.json) being built.
29
+ * @returns {Promise<Browser>} The running Playwright browser - close it yourself (browser.close()) once done with it.
30
+ * @throws {Error} With install instructions when playwright is not installed.
31
31
  */
32
32
  exports.loadPlaywright = loadPlaywright;
33
33
  const launchBrowser = (load = loadPlaywright, projectPath = process.cwd()) => load(projectPath).chromium.launch();
@@ -1,21 +1,21 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.minifyFor = void 0;
7
- var _gulp = require("gulp");
8
- var _gulpUglifyEs = _interopRequireDefault(require("gulp-uglify-es"));
9
- var _gulpRename = _interopRequireDefault(require("gulp-rename"));
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- const uglify = Object.hasOwn(_gulpUglifyEs.default, 'default') ? _gulpUglifyEs.default.default : _gulpUglifyEs.default;
12
-
13
- /**
14
- * Minify files and rename the output with '.min' extension.
15
- * @memberOf module:partials
16
- * @returns {*}
17
- */
18
- const minifyFor = (srcSearch, destination) => (0, _gulp.src)(srcSearch).pipe(uglify()).pipe((0, _gulpRename.default)({
19
- extname: '.min.js'
20
- })).pipe((0, _gulp.dest)(destination));
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.minifyFor = void 0;
7
+ var _gulp = require("gulp");
8
+ var _gulpUglifyEs = _interopRequireDefault(require("gulp-uglify-es"));
9
+ var _gulpRename = _interopRequireDefault(require("gulp-rename"));
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ const uglify = Object.hasOwn(_gulpUglifyEs.default, 'default') ? _gulpUglifyEs.default.default : _gulpUglifyEs.default;
12
+
13
+ /**
14
+ * Minify files and rename the output with '.min' extension.
15
+ * @memberOf module:partials
16
+ * @returns {*}
17
+ */
18
+ const minifyFor = (srcSearch, destination) => (0, _gulp.src)(srcSearch).pipe(uglify()).pipe((0, _gulpRename.default)({
19
+ extname: '.min.js'
20
+ })).pipe((0, _gulp.dest)(destination));
21
21
  exports.minifyFor = minifyFor;