js-build-tools 6.5.0 → 6.7.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 (169) hide show
  1. package/LICENSE +674 -674
  2. package/README.md +762 -692
  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/clean.js +5 -5
  20. package/dist/partials/copyFor.js +9 -9
  21. package/dist/partials/distFor.js +6 -6
  22. package/dist/partials/distForSrc.js +5 -5
  23. package/dist/partials/distSeries.js +7 -7
  24. package/dist/partials/imagesFor.js +93 -56
  25. package/dist/partials/jsdocDocsFor.js +46 -46
  26. package/dist/partials/lintSource.js +51 -51
  27. package/dist/partials/loadPeer.js +99 -99
  28. package/dist/partials/loadPlaywright.js +14 -14
  29. package/dist/partials/minifyFor.js +20 -20
  30. package/dist/partials/neostandardLint.js +175 -175
  31. package/dist/partials/readmeTemplate.js +4 -4
  32. package/dist/partials/removeDirectory.js +11 -11
  33. package/dist/partials/resolveDocsMethod.js +6 -6
  34. package/dist/partials/runOnChange.js +31 -31
  35. package/dist/partials/sassFor.js +6 -6
  36. package/dist/partials/serveStatic.js +9 -9
  37. package/dist/partials/tsFor.js +32 -32
  38. package/dist/partials/typeDocsFor.js +57 -51
  39. package/dist/partials.js +176 -176
  40. package/dist/sourceLint.js +18 -18
  41. package/dist/test-helpers/isolateGulpCache.js +24 -24
  42. package/dist/test-helpers/setUp.js +4 -4
  43. package/dist/testFull.js +5 -5
  44. package/dist/testQuick.js +5 -5
  45. package/dist/typeDocs.js +5 -5
  46. package/dist/typeScript.js +4 -4
  47. package/dist/utilities/convertMjsFilesForDocs.js +12 -12
  48. package/dist/utilities/dotGet.js +54 -54
  49. package/dist/utilities/dotNotate.js +79 -79
  50. package/dist/utilities/dotSet.js +45 -45
  51. package/dist/utilities/esmNamedExportsToCjs.js +15 -15
  52. package/dist/utilities/getBundleConfigs.js +9 -9
  53. package/dist/utilities/isObject.js +6 -6
  54. package/dist/utilities/strAfter.js +7 -7
  55. package/dist/utilities/strBefore.js +7 -7
  56. package/dist/watchFull.js +4 -4
  57. package/dist/watchTest.js +4 -4
  58. package/functions/build.mjs +72 -72
  59. package/functions/build.test.mjs +763 -759
  60. package/functions/bundle.mjs +44 -44
  61. package/functions/bundle.test.mjs +219 -219
  62. package/functions/bundleMinify.mjs +16 -16
  63. package/functions/bundleMinify.test.mjs +37 -37
  64. package/functions/compileReadme.mjs +9 -9
  65. package/functions/compileReadme.test.mjs +18 -18
  66. package/functions/copyFiles.mjs +32 -32
  67. package/functions/copyFiles.test.mjs +78 -78
  68. package/functions/copyFonts.mjs +9 -9
  69. package/functions/copyFonts.test.mjs +32 -32
  70. package/functions/default.mjs +12 -12
  71. package/functions/default.test.mjs +33 -33
  72. package/functions/dist.mjs +8 -8
  73. package/functions/dist.test.mjs +44 -44
  74. package/functions/distMinify.mjs +9 -9
  75. package/functions/distMinify.test.mjs +15 -15
  76. package/functions/docs.mjs +13 -13
  77. package/functions/docs.test.mjs +45 -45
  78. package/functions/gulpConfigEntries.test.mjs +23 -23
  79. package/functions/images.mjs +8 -8
  80. package/functions/images.test.mjs +142 -142
  81. package/functions/jsdocDocs.mjs +10 -10
  82. package/functions/jsdocEsmExports.test.mjs +24 -24
  83. package/functions/lint.mjs +9 -9
  84. package/functions/partials/addToReadme.mjs +25 -25
  85. package/functions/partials/addToReadme.test.mjs +34 -34
  86. package/functions/partials/beginWatcher.mjs +9 -9
  87. package/functions/partials/beginWatcher.test.mjs +19 -19
  88. package/functions/partials/clean.mjs +13 -13
  89. package/functions/partials/clean.test.mjs +22 -22
  90. package/functions/partials/copyFor.mjs +15 -15
  91. package/functions/partials/copyFor.test.mjs +53 -53
  92. package/functions/partials/distFor.mjs +22 -22
  93. package/functions/partials/distFor.test.mjs +195 -195
  94. package/functions/partials/distForSrc.mjs +11 -11
  95. package/functions/partials/distForSrc.test.mjs +18 -18
  96. package/functions/partials/distSeries.mjs +21 -21
  97. package/functions/partials/distSeries.test.mjs +34 -34
  98. package/functions/partials/imagesFor.mjs +83 -50
  99. package/functions/partials/imagesFor.test.mjs +287 -229
  100. package/functions/partials/jsdocDocsFor.mjs +163 -152
  101. package/functions/partials/jsdocDocsFor.test.mjs +182 -152
  102. package/functions/partials/lintSource.mjs +41 -41
  103. package/functions/partials/loadPeer.mjs +76 -76
  104. package/functions/partials/loadPeer.test.mjs +58 -58
  105. package/functions/partials/loadPlaywright.mjs +23 -23
  106. package/functions/partials/loadPlaywright.test.mjs +70 -70
  107. package/functions/partials/minifyFor.mjs +15 -15
  108. package/functions/partials/minifyFor.test.mjs +49 -49
  109. package/functions/partials/neostandardLint.mjs +142 -142
  110. package/functions/partials/neostandardLint.test.mjs +131 -131
  111. package/functions/partials/readmeTemplate.mjs +12 -12
  112. package/functions/partials/readmeTemplate.test.mjs +34 -34
  113. package/functions/partials/removeDirectory.mjs +34 -34
  114. package/functions/partials/removeDirectory.test.mjs +72 -72
  115. package/functions/partials/resolveDocsMethod.mjs +10 -10
  116. package/functions/partials/resolveDocsMethod.test.mjs +33 -33
  117. package/functions/partials/runOnChange.mjs +54 -54
  118. package/functions/partials/runOnChange.test.mjs +95 -95
  119. package/functions/partials/sassFor.mjs +25 -25
  120. package/functions/partials/sassFor.test.mjs +81 -81
  121. package/functions/partials/serveStatic.mjs +47 -47
  122. package/functions/partials/serveStatic.test.mjs +71 -71
  123. package/functions/partials/tsFor.mjs +92 -92
  124. package/functions/partials/tsFor.test.mjs +88 -88
  125. package/functions/partials/typeDocsFor.mjs +231 -227
  126. package/functions/partials/typeDocsFor.test.mjs +263 -252
  127. package/functions/partials.mjs +31 -31
  128. package/functions/partials.test.mjs +7 -7
  129. package/functions/sass.mjs +4 -4
  130. package/functions/sass.test.mjs +31 -31
  131. package/functions/sourceLint.mjs +13 -13
  132. package/functions/sourceLint.test.mjs +166 -166
  133. package/functions/test-helpers/isolateGulpCache.mjs +16 -16
  134. package/functions/test-helpers/neostandardLintWithRealNeostandard.mjs +40 -40
  135. package/functions/test-helpers/setUp.mjs +100 -100
  136. package/functions/test-helpers/setUp.test.mjs +19 -19
  137. package/functions/testFull.mjs +17 -17
  138. package/functions/testFull.test.mjs +17 -17
  139. package/functions/testHelpers.mjs +10 -10
  140. package/functions/testHelpers.test.mjs +7 -7
  141. package/functions/testQuick.mjs +17 -17
  142. package/functions/testQuick.test.mjs +17 -17
  143. package/functions/typeDocs.mjs +9 -9
  144. package/functions/typeDocs.test.mjs +11 -11
  145. package/functions/typeScript.mjs +8 -8
  146. package/functions/typeScript.test.mjs +11 -11
  147. package/functions/utilities/convertMjsFilesForDocs.mjs +34 -34
  148. package/functions/utilities/convertMjsFilesForDocs.test.mjs +58 -58
  149. package/functions/utilities/dotGet.mjs +49 -49
  150. package/functions/utilities/dotNotate.mjs +73 -73
  151. package/functions/utilities/dotNotate.test.mjs +41 -41
  152. package/functions/utilities/dotSet.mjs +40 -40
  153. package/functions/utilities/esmNamedExportsToCjs.mjs +30 -30
  154. package/functions/utilities/esmNamedExportsToCjs.test.mjs +47 -47
  155. package/functions/utilities/getBundleConfigs.mjs +30 -30
  156. package/functions/utilities/isObject.mjs +8 -8
  157. package/functions/utilities/strAfter.mjs +12 -12
  158. package/functions/utilities/strBefore.mjs +12 -12
  159. package/functions/watchFull.mjs +9 -9
  160. package/functions/watchFull.test.mjs +41 -41
  161. package/functions/watchTest.mjs +10 -10
  162. package/functions/watchTest.test.mjs +49 -49
  163. package/gulp.config.js +4 -4
  164. package/gulp.config.mjs +344 -327
  165. package/gulpfile.base.js +51 -51
  166. package/gulpfile.base.mjs +29 -29
  167. package/jsdoc.base.js +16 -16
  168. package/jsdoc.esmExports.js +17 -17
  169. package/package.json +146 -145
@@ -1,195 +1,195 @@
1
- import fs from 'fs'
2
- import { Transform, PassThrough } from 'node:stream'
3
- import ts from 'typescript'
4
- import File from 'vinyl'
5
- import * as setUp from '../test-helpers/setUp.mjs'
6
- import { distFor } from './distFor.mjs'
7
- import { countMatches, fileExists } from 'test-filesystem'
8
- import { tsFor } from './tsFor.mjs'
9
-
10
- // tsFor's real implementation loads gulp-ts-compile (a genuine ESM-only package) via a dynamic import() hidden
11
- // from babel's static analysis - necessary for production correctness (see tsFor.mjs's own comments), but this
12
- // project's current CommonJS-transform-based Jest setup cannot execute a real dynamic import at all: it doesn't
13
- // just fail cleanly, it segfaults the whole Jest worker. This fake stands in for it here, doing real (not
14
- // mocked-away) TypeScript transpilation via `ts.transpileModule` so this test still exercises genuine compile
15
- // behavior - gulp-ts-compile's own test suite separately covers its whole-program/cross-file-import behavior.
16
- const fakeLoadTsCompile = () => Promise.resolve((options) => {
17
- const transform = new Transform({
18
- objectMode: true,
19
- transform (file, enc, callback) {
20
- const { outputText } = ts.transpileModule(file.contents.toString(), { compilerOptions: options })
21
- jsStream.push(new File({ cwd: file.cwd, base: file.base, path: file.path.replace(/\.tsx?$/, '.js'), contents: Buffer.from(outputText) }))
22
- callback()
23
- },
24
- flush (callback) {
25
- jsStream.end()
26
- dtsStream.end()
27
- callback()
28
- }
29
- })
30
- const jsStream = new PassThrough({ objectMode: true })
31
- const dtsStream = new PassThrough({ objectMode: true })
32
- transform.js = jsStream
33
- transform.dts = dtsStream
34
- return transform
35
- })
36
-
37
- setUp.setDefaults('test-dist-for')
38
- const gulpConfig = setUp.gulpConfig
39
-
40
- const rawContents = 'const babel = require(\'gulp-babel\')\n' +
41
- 'const { dest, src } = require(\'gulp\')\n' +
42
- 'const typeScript = require(\'./typeScript\')\n' +
43
- 'const gulpConfig = require(\'../gulp.config.js\')\n' +
44
- '\n' +
45
- 'const useTsConfig = gulpConfig.get(\'useTsConfig\')\n' +
46
- '\n' +
47
- 'const defaultSrc = useTsConfig\n' +
48
- ' ? gulpConfig.get(\'distSearch\')\n' +
49
- ' : gulpConfig.get(\'srcSearch\')\n' +
50
- '\n' +
51
- 'const distFor = (srcPath = defaultSrc, destPath = gulpConfig.get(\'distPath\')) => {\n' +
52
- ' let pipedSrc = src(srcPath)\n' +
53
- ' if (useTsConfig) {\n' +
54
- ' // Add the typescript so we can compile then apply babel to those files\n' +
55
- ' pipedSrc = typeScript(pipedSrc)\n' +
56
- ' }\n' +
57
- ' return pipedSrc\n' +
58
- ' .pipe(babel())\n' +
59
- ' .pipe(dest(destPath))\n' +
60
- '}\n' +
61
- '\n' +
62
- 'module.exports = distFor\n'
63
-
64
- const rawTsContents = '// @ts-ignore\n' +
65
- 'import gulpConfig from \'../gulp.config.js\'\n' +
66
- '// @ts-ignore\n' +
67
- 'import typeScript from \'./typeScript.js\'\n' +
68
- '// @ts-ignore\n' +
69
- 'import {dest, src} from \'gulp\'\n' +
70
- '// @ts-ignore\n' +
71
- 'import babel from \'gulp-babel\'\n' +
72
- '\n' +
73
- 'const useTsConfig = gulpConfig.get(\'useTsConfig\')\n' +
74
- '\n' +
75
- 'const defaultSrc: string | Array<any> = useTsConfig\n' +
76
- ' ? gulpConfig.get(\'distSearch\')\n' +
77
- ' : gulpConfig.get(\'srcSearch\')\n' +
78
- '\n' +
79
- '// @ts-ignore\n' +
80
- 'const distFor = (srcPath: string | Array<any> = defaultSrc, destPath: string = gulpConfig.get(\'distPath\')): import(\'readable-stream\').Stream => {\n' +
81
- ' let pipedSrc = src(srcPath)\n' +
82
- ' if (useTsConfig) {\n' +
83
- ' // Add the typescript so we can compile then apply babel to those files\n' +
84
- ' pipedSrc = typeScript(pipedSrc)\n' +
85
- ' }\n' +
86
- ' return pipedSrc\n' +
87
- ' .pipe(babel())\n' +
88
- ' .pipe(dest(destPath))\n' +
89
- '}\n' +
90
- '\n' +
91
- 'export default distFor\n'
92
-
93
- const rawMjsContents = 'import babel from \'gulp-babel\'\n' +
94
- 'import { dest, src } from \'gulp\'\n' +
95
- 'import { distForSrc } from \'./distForSrc.mjs\'\n' +
96
- 'import * as gulpConfig from \'../../gulp.config.mjs\'\n' +
97
- '\n' +
98
- '/**\n' +
99
- ' * Build the distribution for a given source pattern.\n' +
100
- ' * @memberOf module:partials\n' +
101
- ' * @param {string|array} [srcPath=\'src/config/path/dist/for\']\n' +
102
- ' * @param {string} [destPath=\'dist/config/path\']\n' +
103
- ' * @returns {stream.Stream}\n' +
104
- ' */\n' +
105
- 'export const distFor = (srcPath = distForSrc(), destPath = gulpConfig.get(\'dist.to\')) => src(srcPath)\n' +
106
- ' .pipe(babel())\n' +
107
- ' .pipe((result) => console.log(result) || result)\n' +
108
- ' .pipe(dest(destPath))\n'
109
-
110
- beforeEach(setUp.beforeEach)
111
-
112
- afterEach(setUp.afterEach)
113
-
114
- describe('distFor', () => {
115
- test('copies the src directory and babelifies it into the dist directory', done => {
116
- const srcPath = gulpConfig.get('srcPath')
117
- const srcFile = `${srcPath}/distFor.js`
118
- fs.writeFileSync(srcFile, rawContents)
119
- expect.assertions(3)
120
- const oldContents = fs.readFileSync(srcFile).toString()
121
- expect(countMatches(oldContents, 'const ')).toEqual(7)
122
- const distPath = gulpConfig.get('dist.to')
123
- distFor(srcFile)
124
- .on('finish', () => {
125
- expect(fileExists(distPath)).toBeTruthy()
126
- const babelifiedContents = fs.readFileSync(`${distPath}/distFor.js`).toString()
127
- /* There used to be checks here for `const`/`let` being swapped to `var`, and for arrow functions being
128
- compiled down to `function`/`arguments`, but neither happens anymore now that 'browserslist' resolves to
129
- targets that natively support this syntax - there's nothing stable left to count. What still matters -
130
- that babel actually ran and produced a valid CommonJS module - is confirmed by the "use strict" check.
131
- */
132
- expect(countMatches(babelifiedContents, '"use strict"')).toEqual(1)
133
- done()
134
- })
135
- .on('error', error => {
136
- console.error('Encountered error', error)
137
- done()
138
- })
139
- }, 5000)
140
-
141
- test('can process typescript before babel', done => {
142
- // Since adding the additional skip in tsFor if not enabled we need to ensure that we enable typescript for this test.
143
- gulpConfig.set('typescript.enabled', true)
144
- const srcPath = gulpConfig.get('srcPath')
145
- const srcFile = `${srcPath}/distFor.ts`
146
- fs.writeFileSync(srcFile, rawTsContents)
147
- expect.assertions(7)
148
- const oldContents = fs.readFileSync(srcFile).toString()
149
- expect(countMatches(oldContents, 'const ')).toEqual(3)
150
- const distPath = gulpConfig.get('dist.to')
151
- const tsFrom = gulpConfig.get('typescript.from')
152
- const tsTo = gulpConfig.get('typescript.to')
153
- tsFor(tsFrom, tsTo, fakeLoadTsCompile)(() => {
154
- distFor()
155
- .on('finish', () => {
156
- expect(fileExists(distPath)).toBeTruthy()
157
- const babelifiedContents = fs.readFileSync(`${distPath}/distFor.js`).toString()
158
- expect(countMatches(babelifiedContents, '"use strict"')).toEqual(1)
159
- expect(countMatches(babelifiedContents, 'const ')).toEqual(0)
160
- expect(countMatches(babelifiedContents, 'var ')).toEqual(8)
161
- expect(countMatches(babelifiedContents, 'function')).toEqual(1)
162
- expect(countMatches(babelifiedContents, 'Object.defineProperty(exports, "__esModule", {')).toEqual(1)
163
- done()
164
- })
165
- .on('error', error => {
166
- console.error('Encountered error with distFor', error)
167
- done()
168
- })
169
- })
170
- }, 60000)
171
-
172
- test('converts .mjs file extension to .js', done => {
173
- const srcPath = gulpConfig.get('srcPath')
174
- const srcFile = `${srcPath}/distFor.mjs`
175
- fs.writeFileSync(srcFile, rawMjsContents)
176
- // expect.assertions(5)
177
- const oldContents = fs.readFileSync(srcFile).toString()
178
- expect(countMatches(oldContents, '.mjs')).toEqual(2)
179
- const distPath = gulpConfig.get('dist.to')
180
- distFor(srcFile)
181
- .on('finish', () => {
182
- expect(fileExists(distPath)).toBeTruthy()
183
- const babelifiedContents = fs.readFileSync(`${distPath}/distFor.js`).toString()
184
- // A total '.js' substring count is too fragile - it drifts with whichever core-js polyfill modules babel
185
- // happens to pull in. Check specifically for the thing this test is about: the .mjs import extension in
186
- // the source (./distForSrc.mjs) got rewritten to .js in the compiled require path.
187
- expect(countMatches(babelifiedContents, 'distForSrc.js')).toEqual(1)
188
- done()
189
- })
190
- .on('error', error => {
191
- console.error('Encountered error', error)
192
- done()
193
- })
194
- }, 5000)
195
- })
1
+ import fs from 'fs'
2
+ import { Transform, PassThrough } from 'node:stream'
3
+ import ts from 'typescript'
4
+ import File from 'vinyl'
5
+ import * as setUp from '../test-helpers/setUp.mjs'
6
+ import { distFor } from './distFor.mjs'
7
+ import { countMatches, fileExists } from 'test-filesystem'
8
+ import { tsFor } from './tsFor.mjs'
9
+
10
+ // tsFor's real implementation loads gulp-ts-compile (a genuine ESM-only package) via a dynamic import() hidden
11
+ // from babel's static analysis - necessary for production correctness (see tsFor.mjs's own comments), but this
12
+ // project's current CommonJS-transform-based Jest setup cannot execute a real dynamic import at all: it doesn't
13
+ // just fail cleanly, it segfaults the whole Jest worker. This fake stands in for it here, doing real (not
14
+ // mocked-away) TypeScript transpilation via `ts.transpileModule` so this test still exercises genuine compile
15
+ // behavior - gulp-ts-compile's own test suite separately covers its whole-program/cross-file-import behavior.
16
+ const fakeLoadTsCompile = () => Promise.resolve((options) => {
17
+ const transform = new Transform({
18
+ objectMode: true,
19
+ transform (file, enc, callback) {
20
+ const { outputText } = ts.transpileModule(file.contents.toString(), { compilerOptions: options })
21
+ jsStream.push(new File({ cwd: file.cwd, base: file.base, path: file.path.replace(/\.tsx?$/, '.js'), contents: Buffer.from(outputText) }))
22
+ callback()
23
+ },
24
+ flush (callback) {
25
+ jsStream.end()
26
+ dtsStream.end()
27
+ callback()
28
+ }
29
+ })
30
+ const jsStream = new PassThrough({ objectMode: true })
31
+ const dtsStream = new PassThrough({ objectMode: true })
32
+ transform.js = jsStream
33
+ transform.dts = dtsStream
34
+ return transform
35
+ })
36
+
37
+ setUp.setDefaults('test-dist-for')
38
+ const gulpConfig = setUp.gulpConfig
39
+
40
+ const rawContents = 'const babel = require(\'gulp-babel\')\n' +
41
+ 'const { dest, src } = require(\'gulp\')\n' +
42
+ 'const typeScript = require(\'./typeScript\')\n' +
43
+ 'const gulpConfig = require(\'../gulp.config.js\')\n' +
44
+ '\n' +
45
+ 'const useTsConfig = gulpConfig.get(\'useTsConfig\')\n' +
46
+ '\n' +
47
+ 'const defaultSrc = useTsConfig\n' +
48
+ ' ? gulpConfig.get(\'distSearch\')\n' +
49
+ ' : gulpConfig.get(\'srcSearch\')\n' +
50
+ '\n' +
51
+ 'const distFor = (srcPath = defaultSrc, destPath = gulpConfig.get(\'distPath\')) => {\n' +
52
+ ' let pipedSrc = src(srcPath)\n' +
53
+ ' if (useTsConfig) {\n' +
54
+ ' // Add the typescript so we can compile then apply babel to those files\n' +
55
+ ' pipedSrc = typeScript(pipedSrc)\n' +
56
+ ' }\n' +
57
+ ' return pipedSrc\n' +
58
+ ' .pipe(babel())\n' +
59
+ ' .pipe(dest(destPath))\n' +
60
+ '}\n' +
61
+ '\n' +
62
+ 'module.exports = distFor\n'
63
+
64
+ const rawTsContents = '// @ts-ignore\n' +
65
+ 'import gulpConfig from \'../gulp.config.js\'\n' +
66
+ '// @ts-ignore\n' +
67
+ 'import typeScript from \'./typeScript.js\'\n' +
68
+ '// @ts-ignore\n' +
69
+ 'import {dest, src} from \'gulp\'\n' +
70
+ '// @ts-ignore\n' +
71
+ 'import babel from \'gulp-babel\'\n' +
72
+ '\n' +
73
+ 'const useTsConfig = gulpConfig.get(\'useTsConfig\')\n' +
74
+ '\n' +
75
+ 'const defaultSrc: string | Array<any> = useTsConfig\n' +
76
+ ' ? gulpConfig.get(\'distSearch\')\n' +
77
+ ' : gulpConfig.get(\'srcSearch\')\n' +
78
+ '\n' +
79
+ '// @ts-ignore\n' +
80
+ 'const distFor = (srcPath: string | Array<any> = defaultSrc, destPath: string = gulpConfig.get(\'distPath\')): import(\'readable-stream\').Stream => {\n' +
81
+ ' let pipedSrc = src(srcPath)\n' +
82
+ ' if (useTsConfig) {\n' +
83
+ ' // Add the typescript so we can compile then apply babel to those files\n' +
84
+ ' pipedSrc = typeScript(pipedSrc)\n' +
85
+ ' }\n' +
86
+ ' return pipedSrc\n' +
87
+ ' .pipe(babel())\n' +
88
+ ' .pipe(dest(destPath))\n' +
89
+ '}\n' +
90
+ '\n' +
91
+ 'export default distFor\n'
92
+
93
+ const rawMjsContents = 'import babel from \'gulp-babel\'\n' +
94
+ 'import { dest, src } from \'gulp\'\n' +
95
+ 'import { distForSrc } from \'./distForSrc.mjs\'\n' +
96
+ 'import * as gulpConfig from \'../../gulp.config.mjs\'\n' +
97
+ '\n' +
98
+ '/**\n' +
99
+ ' * Build the distribution for a given source pattern.\n' +
100
+ ' * @memberOf module:partials\n' +
101
+ ' * @param {string|array} [srcPath=\'src/config/path/dist/for\']\n' +
102
+ ' * @param {string} [destPath=\'dist/config/path\']\n' +
103
+ ' * @returns {stream.Stream}\n' +
104
+ ' */\n' +
105
+ 'export const distFor = (srcPath = distForSrc(), destPath = gulpConfig.get(\'dist.to\')) => src(srcPath)\n' +
106
+ ' .pipe(babel())\n' +
107
+ ' .pipe((result) => console.log(result) || result)\n' +
108
+ ' .pipe(dest(destPath))\n'
109
+
110
+ beforeEach(setUp.beforeEach)
111
+
112
+ afterEach(setUp.afterEach)
113
+
114
+ describe('distFor', () => {
115
+ test('copies the src directory and babelifies it into the dist directory', done => {
116
+ const srcPath = gulpConfig.get('srcPath')
117
+ const srcFile = `${srcPath}/distFor.js`
118
+ fs.writeFileSync(srcFile, rawContents)
119
+ expect.assertions(3)
120
+ const oldContents = fs.readFileSync(srcFile).toString()
121
+ expect(countMatches(oldContents, 'const ')).toEqual(7)
122
+ const distPath = gulpConfig.get('dist.to')
123
+ distFor(srcFile)
124
+ .on('finish', () => {
125
+ expect(fileExists(distPath)).toBeTruthy()
126
+ const babelifiedContents = fs.readFileSync(`${distPath}/distFor.js`).toString()
127
+ /* There used to be checks here for `const`/`let` being swapped to `var`, and for arrow functions being
128
+ compiled down to `function`/`arguments`, but neither happens anymore now that 'browserslist' resolves to
129
+ targets that natively support this syntax - there's nothing stable left to count. What still matters -
130
+ that babel actually ran and produced a valid CommonJS module - is confirmed by the "use strict" check.
131
+ */
132
+ expect(countMatches(babelifiedContents, '"use strict"')).toEqual(1)
133
+ done()
134
+ })
135
+ .on('error', error => {
136
+ console.error('Encountered error', error)
137
+ done()
138
+ })
139
+ }, 5000)
140
+
141
+ test('can process typescript before babel', done => {
142
+ // Since adding the additional skip in tsFor if not enabled we need to ensure that we enable typescript for this test.
143
+ gulpConfig.set('typescript.enabled', true)
144
+ const srcPath = gulpConfig.get('srcPath')
145
+ const srcFile = `${srcPath}/distFor.ts`
146
+ fs.writeFileSync(srcFile, rawTsContents)
147
+ expect.assertions(7)
148
+ const oldContents = fs.readFileSync(srcFile).toString()
149
+ expect(countMatches(oldContents, 'const ')).toEqual(3)
150
+ const distPath = gulpConfig.get('dist.to')
151
+ const tsFrom = gulpConfig.get('typescript.from')
152
+ const tsTo = gulpConfig.get('typescript.to')
153
+ tsFor(tsFrom, tsTo, fakeLoadTsCompile)(() => {
154
+ distFor()
155
+ .on('finish', () => {
156
+ expect(fileExists(distPath)).toBeTruthy()
157
+ const babelifiedContents = fs.readFileSync(`${distPath}/distFor.js`).toString()
158
+ expect(countMatches(babelifiedContents, '"use strict"')).toEqual(1)
159
+ expect(countMatches(babelifiedContents, 'const ')).toEqual(0)
160
+ expect(countMatches(babelifiedContents, 'var ')).toEqual(8)
161
+ expect(countMatches(babelifiedContents, 'function')).toEqual(1)
162
+ expect(countMatches(babelifiedContents, 'Object.defineProperty(exports, "__esModule", {')).toEqual(1)
163
+ done()
164
+ })
165
+ .on('error', error => {
166
+ console.error('Encountered error with distFor', error)
167
+ done()
168
+ })
169
+ })
170
+ }, 60000)
171
+
172
+ test('converts .mjs file extension to .js', done => {
173
+ const srcPath = gulpConfig.get('srcPath')
174
+ const srcFile = `${srcPath}/distFor.mjs`
175
+ fs.writeFileSync(srcFile, rawMjsContents)
176
+ // expect.assertions(5)
177
+ const oldContents = fs.readFileSync(srcFile).toString()
178
+ expect(countMatches(oldContents, '.mjs')).toEqual(2)
179
+ const distPath = gulpConfig.get('dist.to')
180
+ distFor(srcFile)
181
+ .on('finish', () => {
182
+ expect(fileExists(distPath)).toBeTruthy()
183
+ const babelifiedContents = fs.readFileSync(`${distPath}/distFor.js`).toString()
184
+ // A total '.js' substring count is too fragile - it drifts with whichever core-js polyfill modules babel
185
+ // happens to pull in. Check specifically for the thing this test is about: the .mjs import extension in
186
+ // the source (./distForSrc.mjs) got rewritten to .js in the compiled require path.
187
+ expect(countMatches(babelifiedContents, 'distForSrc.js')).toEqual(1)
188
+ done()
189
+ })
190
+ .on('error', error => {
191
+ console.error('Encountered error', error)
192
+ done()
193
+ })
194
+ }, 5000)
195
+ })
@@ -1,11 +1,11 @@
1
- import * as gulpConfig from '../../gulp.config.mjs'
2
-
3
- /**
4
- * Retrieve the correct distFor search path based on TS Config.
5
- * @memberOf module:partials
6
- * @param {module:gulpConfig~FlagStringSetting} [useTs='config/for/ts']
7
- * @returns {string}
8
- */
9
- export const distForSrc = (useTs = gulpConfig.get('typescript.enabled')) => useTs
10
- ? gulpConfig.get('browser.from')
11
- : gulpConfig.get('dist.from')
1
+ import * as gulpConfig from '../../gulp.config.mjs'
2
+
3
+ /**
4
+ * Retrieve the correct distFor search path based on TS Config.
5
+ * @memberOf module:partials
6
+ * @param {module:gulpConfig~FlagStringSetting} [useTs='config/for/ts']
7
+ * @returns {string}
8
+ */
9
+ export const distForSrc = (useTs = gulpConfig.get('typescript.enabled')) => useTs
10
+ ? gulpConfig.get('browser.from')
11
+ : gulpConfig.get('dist.from')
@@ -1,18 +1,18 @@
1
- import * as setUp from '../test-helpers/setUp.mjs'
2
- import { distForSrc } from './distForSrc.mjs'
3
-
4
- const gulpConfig = setUp.gulpConfig
5
-
6
- describe('distForSrc', () => {
7
- test('typescript.enabled as false returns srcSearch', () => {
8
- expect.assertions(1)
9
- gulpConfig.set('typescript.enabled', false)
10
- expect(distForSrc()).toBe(gulpConfig.get('dist.from'))
11
- })
12
-
13
- test('typescript.enabled as true returns distSearch', () => {
14
- expect.assertions(1)
15
- gulpConfig.set('typescript.enabled', true)
16
- expect(distForSrc()).toBe(gulpConfig.get('browser.from'))
17
- })
18
- })
1
+ import * as setUp from '../test-helpers/setUp.mjs'
2
+ import { distForSrc } from './distForSrc.mjs'
3
+
4
+ const gulpConfig = setUp.gulpConfig
5
+
6
+ describe('distForSrc', () => {
7
+ test('typescript.enabled as false returns srcSearch', () => {
8
+ expect.assertions(1)
9
+ gulpConfig.set('typescript.enabled', false)
10
+ expect(distForSrc()).toBe(gulpConfig.get('dist.from'))
11
+ })
12
+
13
+ test('typescript.enabled as true returns distSearch', () => {
14
+ expect.assertions(1)
15
+ gulpConfig.set('typescript.enabled', true)
16
+ expect(distForSrc()).toBe(gulpConfig.get('browser.from'))
17
+ })
18
+ })
@@ -1,21 +1,21 @@
1
- import * as gulpConfig from '../../gulp.config.mjs'
2
- import { distFor } from './distFor.mjs'
3
- import { distForSrc } from './distForSrc.mjs'
4
- import { series } from 'gulp'
5
- import { tsFor } from './tsFor.mjs'
6
-
7
- /**
8
- * When using TypeScript, ensure that we process the ts first then run babel (dist)
9
- * @memberOf module:partials
10
- * @param {string} [srcPath='src/config/path/dist/for']
11
- * @param {string} [distFinalPath='dist/config/path']
12
- * @param {string} [tsSearch='ts/search/config/path']
13
- * @returns {function(null=): stream.Stream}
14
- */
15
- export const distSeries = (srcPath = distForSrc(), distFinalPath = gulpConfig.get('dist.to'), tsSearch = gulpConfig.get('typescript.from')) => {
16
- const typescript = tsFor(tsSearch, distFinalPath)
17
- const dist = () => distFor(srcPath, distFinalPath)
18
- return gulpConfig.get('typescript.enabled')
19
- ? series(typescript, dist)
20
- : dist
21
- }
1
+ import * as gulpConfig from '../../gulp.config.mjs'
2
+ import { distFor } from './distFor.mjs'
3
+ import { distForSrc } from './distForSrc.mjs'
4
+ import { series } from 'gulp'
5
+ import { tsFor } from './tsFor.mjs'
6
+
7
+ /**
8
+ * When using TypeScript, ensure that we process the ts first then run babel (dist)
9
+ * @memberOf module:partials
10
+ * @param {string} [srcPath='src/config/path/dist/for']
11
+ * @param {string} [distFinalPath='dist/config/path']
12
+ * @param {string} [tsSearch='ts/search/config/path']
13
+ * @returns {function(null=): stream.Stream}
14
+ */
15
+ export const distSeries = (srcPath = distForSrc(), distFinalPath = gulpConfig.get('dist.to'), tsSearch = gulpConfig.get('typescript.from')) => {
16
+ const typescript = tsFor(tsSearch, distFinalPath)
17
+ const dist = () => distFor(srcPath, distFinalPath)
18
+ return gulpConfig.get('typescript.enabled')
19
+ ? series(typescript, dist)
20
+ : dist
21
+ }
@@ -1,34 +1,34 @@
1
- import * as setUp from '../test-helpers/setUp.mjs'
2
- import { distSeries } from './distSeries.mjs'
3
- import { tsFor } from './tsFor.mjs'
4
- import { distFor } from './distFor.mjs'
5
-
6
- const gulpConfig = setUp.gulpConfig
7
-
8
- const genericFunction = () => Promise.resolve(true)
9
-
10
- jest.mock('./distFor.mjs', () => ({ distFor: jest.fn(genericFunction) }))
11
- jest.mock('./tsFor.mjs', () => ({ tsFor: jest.fn(() => genericFunction) }))
12
-
13
- describe('distSeries', () => {
14
- test('when not using ts config only returns runnable distFor', done => {
15
- gulpConfig.set('typescript.enabled', false)
16
- expect.assertions(1)
17
- distSeries()()
18
- setTimeout(() => {
19
- expect(distFor).toHaveBeenCalledWith(gulpConfig.get('dist.from'), gulpConfig.get('dist.to'))
20
- done()
21
- }, 500)
22
- })
23
-
24
- test('when using ts config returns runnable series of tsFor and distFor', done => {
25
- gulpConfig.set('typescript.enabled', true)
26
- expect.assertions(2)
27
- distSeries()()
28
- setTimeout(() => {
29
- expect(tsFor).toHaveBeenCalledWith(gulpConfig.get('typescript.from'), gulpConfig.get('dist.to'))
30
- expect(distFor).toHaveBeenCalledWith(gulpConfig.get('browser.from'), gulpConfig.get('dist.to'))
31
- done()
32
- }, 500)
33
- })
34
- })
1
+ import * as setUp from '../test-helpers/setUp.mjs'
2
+ import { distSeries } from './distSeries.mjs'
3
+ import { tsFor } from './tsFor.mjs'
4
+ import { distFor } from './distFor.mjs'
5
+
6
+ const gulpConfig = setUp.gulpConfig
7
+
8
+ const genericFunction = () => Promise.resolve(true)
9
+
10
+ jest.mock('./distFor.mjs', () => ({ distFor: jest.fn(genericFunction) }))
11
+ jest.mock('./tsFor.mjs', () => ({ tsFor: jest.fn(() => genericFunction) }))
12
+
13
+ describe('distSeries', () => {
14
+ test('when not using ts config only returns runnable distFor', done => {
15
+ gulpConfig.set('typescript.enabled', false)
16
+ expect.assertions(1)
17
+ distSeries()()
18
+ setTimeout(() => {
19
+ expect(distFor).toHaveBeenCalledWith(gulpConfig.get('dist.from'), gulpConfig.get('dist.to'))
20
+ done()
21
+ }, 500)
22
+ })
23
+
24
+ test('when using ts config returns runnable series of tsFor and distFor', done => {
25
+ gulpConfig.set('typescript.enabled', true)
26
+ expect.assertions(2)
27
+ distSeries()()
28
+ setTimeout(() => {
29
+ expect(tsFor).toHaveBeenCalledWith(gulpConfig.get('typescript.from'), gulpConfig.get('dist.to'))
30
+ expect(distFor).toHaveBeenCalledWith(gulpConfig.get('browser.from'), gulpConfig.get('dist.to'))
31
+ done()
32
+ }, 500)
33
+ })
34
+ })