js-build-tools 5.3.0 → 5.3.2

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.
@@ -2,7 +2,7 @@ import fs from 'fs'
2
2
  import path from 'node:path'
3
3
  import ts from 'typescript'
4
4
  import * as setUp from '../test-helpers/setUp.mjs'
5
- import { describeExports, loadTypeDoc, typeDocsFor, writeDocEntries } from './typeDocsFor.mjs'
5
+ import { describeExports, describeFile, describeFolder, loadTypeDoc, typeDocsFor, writeDocEntries } from './typeDocsFor.mjs'
6
6
 
7
7
  setUp.setDefaults('test-type-docs-for')
8
8
  const gulpConfig = setUp.gulpConfig
@@ -19,7 +19,7 @@ beforeEach(
19
19
  write(`${srcPath}/point/add.ts`, '/** Add two numbers. */\nconst add = (a: number, b: number): number => a + b\n\nexport default add\n')
20
20
  write(`${srcPath}/point/get-name.ts`, 'export default function getName (): string { return "name" }\n')
21
21
  write(`${srcPath}/point/types.ts`, 'export interface Point { x: number, y: number }\nexport type Axis = keyof Point\n')
22
- write(`${srcPath}/point/index.ts`, "import add from './add'\nexport default { add }\n")
22
+ write(`${srcPath}/point/index.ts`, "/**\n * Points of a matrix and the maths on them.\n * A second line.\n * @file Not part of the description\n * @module point\n */\nimport add from './add'\nexport default { add }\n")
23
23
  write(`${srcPath}/point/add.test.ts`, "test('adds', () => {})\n")
24
24
  write(`${srcPath}/point/add.d.ts`, 'export {}\n')
25
25
  write(`${srcPath}/line/length.ts`, 'export const length = 5\nexport default length\n')
@@ -54,6 +54,30 @@ describe('describeExports', () => {
54
54
  })
55
55
  })
56
56
 
57
+ describe('describeFolder', () => {
58
+ test('is the text of the first comment of the index file, without its tags', () => {
59
+ expect(describeFolder(`${gulpConfig.get('srcPath')}/point`)).toBe('Points of a matrix and the maths on them.\nA second line.')
60
+ })
61
+
62
+ test('is empty without an index file, or a comment in it', () => {
63
+ expect(describeFolder(`${gulpConfig.get('srcPath')}/line`)).toBe('')
64
+ write(`${gulpConfig.get('srcPath')}/bare/index.ts`, "import a from './a'\nexport default { a }\n")
65
+ expect(describeFolder(`${gulpConfig.get('srcPath')}/bare`)).toBe('')
66
+ })
67
+ })
68
+
69
+ describe('describeFile', () => {
70
+ test('is the header comment of a file, without its tags', () => {
71
+ write(`${gulpConfig.get('srcPath')}/header.ts`, "/**\n * Simulate what a user does.\n * @module simulate\n */\nimport a from './a'\nexport default a\n")
72
+ expect(describeFile(`${gulpConfig.get('srcPath')}/header.ts`)).toBe('Simulate what a user does.')
73
+ })
74
+
75
+ test('is empty when the first comment documents a declaration', () => {
76
+ write(`${gulpConfig.get('srcPath')}/declaration.ts`, '/**\n * Add two numbers.\n */\nconst add = (a: number, b: number) => a + b\nexport default add\n')
77
+ expect(describeFile(`${gulpConfig.get('srcPath')}/declaration.ts`)).toBe('')
78
+ })
79
+ })
80
+
57
81
  describe('writeDocEntries', () => {
58
82
  test('writes one entry file for each folder which has source', () => {
59
83
  const entryDir = `${gulpConfig.get('srcPath')}/../entries`
@@ -65,12 +89,13 @@ describe('writeDocEntries', () => {
65
89
  const entryDir = `${gulpConfig.get('srcPath')}/../entries`
66
90
  writeDocEntries(ts, gulpConfig.get('srcPath'), entryDir)
67
91
  const absoluteSrc = path.resolve(gulpConfig.get('srcPath')).split(path.sep).join('/')
68
- expect(fs.readFileSync(`${entryDir}/point.ts`, 'utf8').trim().split('\n')).toEqual([
92
+ const exportLines = file => fs.readFileSync(file, 'utf8').trim().split('\n').filter(line => line.startsWith('export'))
93
+ expect(exportLines(`${entryDir}/point.ts`)).toEqual([
69
94
  `export { default as add } from '${absoluteSrc}/point/add'`,
70
95
  `export { default as getName } from '${absoluteSrc}/point/get-name'`,
71
96
  `export * from '${absoluteSrc}/point/types'`
72
97
  ])
73
- expect(fs.readFileSync(`${entryDir}/line.ts`, 'utf8').trim().split('\n')).toEqual([
98
+ expect(exportLines(`${entryDir}/line.ts`)).toEqual([
74
99
  `export { default as length } from '${absoluteSrc}/line/length'`,
75
100
  `export * from '${absoluteSrc}/line/length'`
76
101
  ])
@@ -80,7 +105,28 @@ describe('writeDocEntries', () => {
80
105
  const entryDir = `${gulpConfig.get('srcPath')}/../entries`
81
106
  writeDocEntries(ts, gulpConfig.get('srcPath'), entryDir)
82
107
  const entry = fs.readFileSync(`${entryDir}/point.ts`, 'utf8')
83
- expect(entry).not.toMatch(/index|\.test|add\.d/)
108
+ expect(entry).not.toMatch(/from '.*(index|\.test|add\.d)/)
109
+ })
110
+
111
+ test('describes the module with the first comment of the index file of the folder', () => {
112
+ const entryDir = `${gulpConfig.get('srcPath')}/../entries`
113
+ writeDocEntries(ts, gulpConfig.get('srcPath'), entryDir)
114
+ expect(fs.readFileSync(`${entryDir}/point.ts`, 'utf8')).toMatch(/^\/\*\*\n \* Points of a matrix and the maths on them\.\n \* A second line\.\n \* @module\n \*\/\n\nexport/)
115
+ // A folder without an index file has no comment
116
+ expect(fs.readFileSync(`${entryDir}/line.ts`, 'utf8').startsWith('export')).toBe(true)
117
+ })
118
+
119
+ test('makes a module of a file which sits beside the folders, but not of the barrel files', () => {
120
+ const srcPath = gulpConfig.get('srcPath')
121
+ write(`${srcPath}/simulate.ts`, "/**\n * Simulate what a user does.\n */\nimport add from './point/add'\nexport const click = () => add(1, 2)\nexport default { click }\n")
122
+ write(`${srcPath}/simulate.test.ts`, "test('x', () => {})\n")
123
+ const entryDir = `${srcPath}/../entries`
124
+ const entries = writeDocEntries(ts, srcPath, entryDir)
125
+ expect(entries.map(entry => path.basename(entry)).sort()).toEqual(['line.ts', 'point.ts', 'simulate.ts'])
126
+ const absoluteSrc = path.resolve(srcPath).split(path.sep).join('/')
127
+ expect(fs.readFileSync(`${entryDir}/simulate.ts`, 'utf8')).toBe(
128
+ `/**\n * Simulate what a user does.\n * @module\n */\n\nexport { default as simulate } from '${absoluteSrc}/simulate'\nexport * from '${absoluteSrc}/simulate'\n`
129
+ )
84
130
  })
85
131
 
86
132
  test('makes one entry called index when the source has no folders', () => {
@@ -15,6 +15,7 @@ export { distFor } from './partials/distFor.mjs'
15
15
  export { distForSrc } from './partials/distForSrc.mjs'
16
16
  export { distSeries } from './partials/distSeries.mjs'
17
17
  export { imagesFor } from './partials/imagesFor.mjs'
18
+ export { importModule, importPeer, requirePeer } from './partials/loadPeer.mjs'
18
19
  export { minifyFor } from './partials/minifyFor.mjs'
19
20
  export { readmeTemplate } from './partials/readmeTemplate.mjs'
20
21
  export { removeDirectory } from './partials/removeDirectory.mjs'
@@ -2,6 +2,6 @@ import * as partials from './partials.mjs'
2
2
 
3
3
  describe('partials', () => {
4
4
  test('is object with all partial exports', () => {
5
- expect(Object.keys(partials).length).toBe(16)
5
+ expect(Object.keys(partials).length).toBe(19)
6
6
  })
7
7
  })
package/gulp.config.mjs CHANGED
@@ -49,8 +49,8 @@ import { fileExists } from 'test-filesystem'
49
49
  * Configurations for building the browser files.
50
50
  * @typedef {Object<string, Setting>} module:gulpConfig~BrowserConfig
51
51
  * @property {BooleanSetting} enabled - 'true' to generate browser bundled files; 'false' for node environment only
52
- * @property {StringSetting} from - The name to use for the browser-bundled output file (.js will be appended).
53
- * @property {StringSetting} name - The search pattern used for retrieving compiled distribution files.
52
+ * @property {StringSetting} from - The search pattern used for retrieving compiled distribution files.
53
+ * @property {StringSetting} name - The name to use for the browser-bundled output file (.js will be appended).
54
54
  * @property {StringSetting} to - The output directory for browser-bundled files.
55
55
  * @property {ArrayableSetting} ignore - Module names or file paths which resolve to an empty object ({}) in the
56
56
  * bundle instead of their real contents. For a dependency which is only reached because it is the default value of
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-build-tools",
3
- "version": "5.3.0",
3
+ "version": "5.3.2",
4
4
  "description": "Standardised build process with gulp.",
5
5
  "main": "gulpfile.base.js",
6
6
  "exports": {