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.
- package/README.md +46 -3
- package/dist/build.js +40 -38
- package/dist/build.min.js +1 -1
- package/dist/bundle.js +24 -23
- package/dist/bundle.min.js +1 -1
- package/dist/bundleMinify.js +14 -13
- package/dist/bundleMinify.min.js +1 -1
- package/dist/compileReadme.js +7 -7
- package/dist/copyFonts.js +14 -13
- package/dist/copyFonts.min.js +1 -1
- package/dist/default.js +16 -15
- package/dist/default.min.js +1 -1
- package/dist/dist.js +7 -7
- package/dist/distMinify.js +14 -13
- package/dist/distMinify.min.js +1 -1
- package/dist/images.js +7 -7
- package/dist/partials/addToReadme.js +3 -2
- package/dist/partials/beginWatcher.js +13 -12
- package/dist/partials/clean.js +15 -14
- package/dist/partials/distFor.js +22 -21
- package/dist/partials/distForSrc.js +12 -11
- package/dist/partials/distSeries.js +20 -19
- package/dist/partials/imagesFor.js +2 -1
- package/dist/partials/loadPeer.js +70 -70
- package/dist/partials/neostandardLint.js +163 -0
- package/dist/partials/readmeTemplate.js +15 -14
- package/dist/partials/runOnChange.js +29 -28
- package/dist/partials/sassFor.js +29 -28
- package/dist/partials/tsFor.js +2 -1
- package/dist/partials/typeDocsFor.js +2 -1
- package/dist/partials.js +136 -136
- package/dist/partials.min.js +1 -1
- package/dist/sass.js +7 -7
- package/dist/sourceLint.js +35 -0
- package/dist/sourceLint.min.js +1 -0
- package/dist/test-helpers/neostandardLintWithRealNeostandard.js +50 -0
- package/dist/test-helpers/setUp.js +2 -1
- package/dist/testFull.js +21 -20
- package/dist/testFull.min.js +1 -1
- package/dist/testHelpers.js +11 -10
- package/dist/testHelpers.min.js +1 -1
- package/dist/testQuick.js +23 -22
- package/dist/testQuick.min.js +1 -1
- package/dist/typeDocs.js +9 -9
- package/dist/typeScript.js +6 -6
- package/dist/utilities/convertMjsFilesForDocs.js +36 -36
- package/dist/utilities/dotNotate.js +48 -46
- package/dist/utilities/esmNamedExportsToCjs.js +18 -18
- package/dist/utilities/getBundleConfigs.js +3 -2
- package/dist/watchFull.js +7 -7
- package/dist/watchTest.js +17 -16
- package/dist/watchTest.min.js +1 -1
- package/functions/build.mjs +9 -8
- package/functions/build.test.mjs +18 -25
- package/functions/bundle.mjs +2 -2
- package/functions/partials/addToReadme.mjs +1 -1
- package/functions/partials/neostandardLint.mjs +130 -0
- package/functions/partials/neostandardLint.test.mjs +117 -0
- package/functions/partials.mjs +1 -1
- package/functions/sourceLint.mjs +24 -0
- package/functions/sourceLint.test.mjs +97 -0
- package/functions/test-helpers/neostandardLintWithRealNeostandard.mjs +40 -0
- package/functions/utilities/dotNotate.mjs +3 -1
- package/functions/utilities/dotNotate.test.mjs +34 -0
- package/functions/utilities/getBundleConfigs.mjs +1 -1
- package/gulp.config.mjs +14 -0
- package/gulpfile.base.js +2 -4
- package/gulpfile.base.mjs +1 -2
- package/package.json +7 -6
- package/dist/bundleLint.js +0 -28
- package/dist/bundleLint.min.js +0 -1
- package/dist/distLint.js +0 -20
- package/dist/distLint.min.js +0 -1
- package/dist/partials/standardLint.js +0 -94
- package/dist/test-helpers/standardLintWithRealStandard.js +0 -28
- package/functions/bundleLint.mjs +0 -18
- package/functions/bundleLint.test.mjs +0 -85
- package/functions/distLint.mjs +0 -12
- package/functions/distLint.test.mjs +0 -62
- package/functions/partials/standardLint.mjs +0 -78
- package/functions/partials/standardLint.test.mjs +0 -99
- package/functions/test-helpers/standardLintWithRealStandard.mjs +0 -21
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import Vinyl from 'vinyl'
|
|
2
|
-
import { Readable } from 'node:stream'
|
|
3
|
-
import { standardLint } from './standardLint.mjs'
|
|
4
|
-
|
|
5
|
-
const makeFile = (contents, filePath = '/project/dist/example.js') => new Vinyl({
|
|
6
|
-
cwd: '/project',
|
|
7
|
-
base: '/project/dist',
|
|
8
|
-
path: filePath,
|
|
9
|
-
contents
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
const run = (transform, files) => new Promise((resolve, reject) => {
|
|
13
|
-
const out = []
|
|
14
|
-
transform.on('data', file => out.push(file)).on('end', () => resolve(out)).on('error', reject)
|
|
15
|
-
files.forEach(file => transform.write(file))
|
|
16
|
-
transform.end()
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
const fakeStandard = (resultFor) => ({
|
|
20
|
-
lintText: jest.fn((text, options) => Promise.resolve(resultFor(text, options)))
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
let logSpy
|
|
24
|
-
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
logSpy = jest.spyOn(console, 'log').mockImplementation(() => {})
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
afterEach(() => {
|
|
30
|
-
logSpy.mockRestore()
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
describe('standardLint', () => {
|
|
34
|
-
test('replaces file contents with the fixed output and hands Standard the file path, cwd and fix option', async () => {
|
|
35
|
-
expect.assertions(3)
|
|
36
|
-
const standard = fakeStandard((text) => [{ messages: [], errorCount: 0, warningCount: 0, output: text.replace(/"/g, '\'') }])
|
|
37
|
-
const [linted] = await run(standardLint({ fix: true }, () => Promise.resolve(standard)), [makeFile(Buffer.from('const a = "b"'))])
|
|
38
|
-
expect(linted.contents.toString()).toEqual('const a = \'b\'')
|
|
39
|
-
expect(standard.lintText).toHaveBeenCalledWith('const a = "b"', { filename: '/project/dist/example.js', cwd: '/project', fix: true })
|
|
40
|
-
expect(linted.path).toEqual('/project/dist/example.js')
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
test('leaves the contents alone when Standard has no fixed output (nothing needed fixing)', async () => {
|
|
44
|
-
expect.assertions(1)
|
|
45
|
-
const standard = fakeStandard(() => [{ messages: [], errorCount: 0, warningCount: 0 }])
|
|
46
|
-
const [linted] = await run(standardLint({}, () => Promise.resolve(standard)), [makeFile(Buffer.from('const a = 1'))])
|
|
47
|
-
expect(linted.contents.toString()).toEqual('const a = 1')
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
test('passes fix: false through so nothing is rewritten', async () => {
|
|
51
|
-
expect.assertions(1)
|
|
52
|
-
const standard = fakeStandard(() => [{ messages: [], errorCount: 0, warningCount: 0 }])
|
|
53
|
-
await run(standardLint({ fix: false }, () => Promise.resolve(standard)), [makeFile(Buffer.from('x'))])
|
|
54
|
-
expect(standard.lintText.mock.calls[0][1].fix).toBe(false)
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
test('passes a file through untouched when the project ignores it (Standard returns no results)', async () => {
|
|
58
|
-
expect.assertions(2)
|
|
59
|
-
const standard = fakeStandard(() => [])
|
|
60
|
-
const [linted] = await run(standardLint({}, () => Promise.resolve(standard)), [makeFile(Buffer.from('var x=1'))])
|
|
61
|
-
expect(linted.contents.toString()).toEqual('var x=1')
|
|
62
|
-
expect(logSpy).toHaveBeenCalledWith('✖ Errors total: 0')
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
test('skips null-content files without linting them', async () => {
|
|
66
|
-
expect.assertions(2)
|
|
67
|
-
const standard = fakeStandard(() => [])
|
|
68
|
-
const [passed] = await run(standardLint({}, () => Promise.resolve(standard)), [makeFile(null)])
|
|
69
|
-
expect(passed.isNull()).toBeTruthy()
|
|
70
|
-
expect(standard.lintText).not.toHaveBeenCalled()
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
test('errors on streaming file contents, which cannot be linted', async () => {
|
|
74
|
-
expect.assertions(1)
|
|
75
|
-
const streamFile = makeFile(Readable.from(['x']))
|
|
76
|
-
await expect(run(standardLint({}, () => Promise.resolve(fakeStandard(() => []))), [streamFile])).rejects.toThrow(/streaming/)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
test('prints per-file problems and a summary of totals across all files, without failing', async () => {
|
|
80
|
-
expect.assertions(5)
|
|
81
|
-
const standard = fakeStandard((text, { filename }) => filename.endsWith('a.js')
|
|
82
|
-
? [{ messages: [{ line: 2, column: 7, message: 'unused b' }, { line: 3, column: 1, message: 'bad thing' }], errorCount: 2, warningCount: 0 }]
|
|
83
|
-
: [{ messages: [{ line: 1, column: 1, message: 'just a warning' }], errorCount: 0, warningCount: 1 }])
|
|
84
|
-
const out = await run(
|
|
85
|
-
standardLint({}, () => Promise.resolve(standard)),
|
|
86
|
-
[makeFile(Buffer.from('a'), '/project/dist/a.js'), makeFile(Buffer.from('b'), '/project/dist/b.js')]
|
|
87
|
-
)
|
|
88
|
-
expect(out).toHaveLength(2)
|
|
89
|
-
expect(logSpy).toHaveBeenCalledWith('dist/a.js')
|
|
90
|
-
expect(logSpy).toHaveBeenCalledWith('line 2:7\tunused b')
|
|
91
|
-
expect(logSpy).toHaveBeenCalledWith('✖ Errors total: 2')
|
|
92
|
-
expect(logSpy).toHaveBeenCalledWith('⚠ Warnings total: 1\n')
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
test('surfaces a failure to load or run Standard as a stream error', async () => {
|
|
96
|
-
expect.assertions(1)
|
|
97
|
-
await expect(run(standardLint({}, () => Promise.reject(new Error('cannot load'))), [makeFile(Buffer.from('x'))])).rejects.toThrow('cannot load')
|
|
98
|
-
})
|
|
99
|
-
})
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { execFileSync } from 'node:child_process'
|
|
2
|
-
|
|
3
|
-
// Jest's CommonJS transform cannot load `standard` (ESM-only) or run a real dynamic import(), so tests that need
|
|
4
|
-
// genuine Standard behavior run the actual `standard` package in a plain Node subprocess instead of faking it.
|
|
5
|
-
const script = 'import { readFileSync } from \'node:fs\'\n' +
|
|
6
|
-
'import standard from \'standard\'\n' +
|
|
7
|
-
'const { text, options } = JSON.parse(readFileSync(0, \'utf8\'))\n' +
|
|
8
|
-
'process.stdout.write(JSON.stringify(await standard.lintText(text, options)))\n'
|
|
9
|
-
|
|
10
|
-
export const loadStandardViaSubprocess = () => Promise.resolve({
|
|
11
|
-
lintText: (text, options) => Promise.resolve().then(() => JSON.parse(execFileSync(
|
|
12
|
-
process.execPath,
|
|
13
|
-
['--input-type=module', '--eval', script],
|
|
14
|
-
{ input: JSON.stringify({ text, options }), encoding: 'utf8', cwd: process.cwd(), maxBuffer: 256 * 1024 * 1024 }
|
|
15
|
-
)))
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
const actual = jest.requireActual('../partials/standardLint.mjs')
|
|
19
|
-
|
|
20
|
-
// Drop-in replacement for the partial module (see jest.mock in the lint/build tests): same API, real Standard.
|
|
21
|
-
export const standardLint = (options) => actual.standardLint(options, loadStandardViaSubprocess)
|