itee-validators 5.6.0 → 6.0.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 (131) hide show
  1. package/.github/workflows/node.js.yml +2 -2
  2. package/.releaserc.mjs +94 -0
  3. package/.tasks/.builds/build-benchmarks.task.mjs +16 -0
  4. package/.tasks/.builds/build-tests.task.mjs +18 -0
  5. package/.tasks/.builds/build-unit-tests.task.mjs +16 -0
  6. package/.tasks/.builds/build.task.mjs +46 -0
  7. package/.tasks/.cleans/clean.task.mjs +23 -0
  8. package/.tasks/.docs/doc.task.mjs +35 -0
  9. package/.tasks/.helps/help.task.mjs +151 -0
  10. package/.tasks/.lints/lint.task.mjs +37 -0
  11. package/.tasks/.patches/patch.task.mjs +13 -0
  12. package/.tasks/.releases/release.task.mjs +26 -0
  13. package/.tasks/.tests/benchmarks/build-benchmarks-backend.task.mjs +42 -0
  14. package/.tasks/{tests/benchmarks/compute-benchmarks.mjs → .tests/benchmarks/compute-benchmarks.task.mjs} +46 -51
  15. package/.tasks/.tests/benchmarks/run-benchmarks-for-backend.task.mjs +39 -0
  16. package/.tasks/.tests/benchmarks/run-benchmarks-for-frontend.task.mjs +41 -0
  17. package/.tasks/.tests/benchmarks/run-benchmarks.task.mjs +18 -0
  18. package/.tasks/{tests/bundling/check-bundling-from-esm-build-import.mjs → .tests/bundling/check-bundling-from-esm-build-import.task.mjs} +31 -75
  19. package/.tasks/.tests/bundling/check-bundling-from-esm-files-direct.task.mjs +77 -0
  20. package/.tasks/.tests/bundling/check-bundling-from-esm-files-import.task.mjs +95 -0
  21. package/.tasks/.tests/bundling/check-bundling.task.mjs +20 -0
  22. package/.tasks/.tests/run-tests.task.mjs +18 -0
  23. package/.tasks/.tests/unit-tests/build-unit-tests-backend.task.mjs +42 -0
  24. package/.tasks/{tests/unit-tests/compute-unit-tests.mjs → .tests/unit-tests/compute-unit-tests.task.mjs} +152 -193
  25. package/.tasks/.tests/unit-tests/run-unit-tests-for-backend.task.mjs +44 -0
  26. package/.tasks/.tests/unit-tests/run-unit-tests-for-frontend.task.mjs +41 -0
  27. package/.tasks/.tests/unit-tests/run-unit-tests.task.mjs +18 -0
  28. package/.tasks/_refresh-gulpfile.task.mjs +65 -0
  29. package/.tasks/_utils.mjs +159 -33
  30. package/.tasks/configs/benchmarks.conf.mjs +57 -0
  31. package/.tasks/configs/build-benchmarks-backend.conf.mjs +51 -0
  32. package/.tasks/configs/build-unit-tests-backend.conf.mjs +46 -0
  33. package/.tasks/configs/build.conf.mjs +354 -0
  34. package/.tasks/configs/check-bundling.conf.mjs +26 -0
  35. package/.tasks/configs/clean.conf.mjs +9 -0
  36. package/.tasks/configs/compute-benchmarks.conf.mjs +28 -0
  37. package/.tasks/configs/compute-unit-tests.conf.mjs +27 -0
  38. package/.tasks/configs/doc.conf.json +50 -0
  39. package/.tasks/configs/eslint.conf.mjs +121 -0
  40. package/.tasks/configs/units.conf.mjs +27 -0
  41. package/.tasks/itee-benchmarks-framework.js +186 -0
  42. package/.tasks/itee-reporter.mjs +217 -0
  43. package/CHANGELOG.md +12 -0
  44. package/builds/itee-validators.cjs.js +53 -15
  45. package/builds/itee-validators.cjs.js.map +1 -1
  46. package/builds/itee-validators.cjs.min.js +36 -35
  47. package/builds/itee-validators.esm.js +25 -2
  48. package/builds/itee-validators.esm.js.map +1 -1
  49. package/builds/itee-validators.esm.min.js +3 -3
  50. package/builds/itee-validators.iife.js +25 -4
  51. package/builds/itee-validators.iife.js.map +1 -1
  52. package/builds/itee-validators.iife.min.js +10 -10
  53. package/package.json +49 -41
  54. package/sources/cores/_cores.js +10 -10
  55. package/sources/cores/arrays/_arrays.js +12 -12
  56. package/sources/cores/arrays/isArrayOfArray.js +2 -2
  57. package/sources/cores/arrays/isArrayOfBoolean.js +3 -3
  58. package/sources/cores/arrays/isArrayOfFunction.js +3 -3
  59. package/sources/cores/arrays/isArrayOfMultiElement.js +1 -1
  60. package/sources/cores/arrays/isArrayOfNull.js +3 -3
  61. package/sources/cores/arrays/isArrayOfNumber.js +3 -3
  62. package/sources/cores/arrays/isArrayOfObject.js +3 -3
  63. package/sources/cores/arrays/isArrayOfSingleElement.js +1 -1
  64. package/sources/cores/arrays/isArrayOfString.js +3 -3
  65. package/sources/cores/arrays/isArrayOfUndefined.js +3 -3
  66. package/sources/cores/arrays/isEmptyArray.js +1 -1
  67. package/sources/cores/booleans/_booleans.js +2 -2
  68. package/sources/cores/booleans/isTrue.js +1 -1
  69. package/sources/cores/cores.js +8 -8
  70. package/sources/cores/functions/_functions.js +1 -1
  71. package/sources/cores/numbers/_numbers.js +6 -6
  72. package/sources/cores/numbers/isNumber.js +3 -3
  73. package/sources/cores/objects/_objects.js +2 -2
  74. package/sources/cores/objects/isEmptyObject.js +1 -1
  75. package/sources/cores/objects/isObject.js +1 -1
  76. package/sources/cores/strings/_strings.js +3 -3
  77. package/sources/cores/strings/isBlankString.js +2 -2
  78. package/sources/cores/strings/isEmptyString.js +1 -1
  79. package/sources/cores/symbols/_symbols.js +1 -1
  80. package/sources/cores/tests/isTestUnitGenerator.js +5 -6
  81. package/sources/cores/typed-arrays/_typedArrays.js +12 -12
  82. package/sources/cores/voids/_voids.js +4 -4
  83. package/sources/cores/voids/isEmpty.js +4 -4
  84. package/sources/file-system/_file-system.js +9 -9
  85. package/sources/file-system/block-devices/_blockDevices.js +3 -3
  86. package/sources/file-system/block-devices/isBlockDevicePath.js +3 -3
  87. package/sources/file-system/block-devices/isValidBlockDevicePath.js +2 -2
  88. package/sources/file-system/character-devices/_characterDevices.js +3 -3
  89. package/sources/file-system/character-devices/isCharacterDevicePath.js +3 -3
  90. package/sources/file-system/character-devices/isValidCharacterDevicePath.js +2 -2
  91. package/sources/file-system/directories/_directories.js +4 -4
  92. package/sources/file-system/directories/isDirectoryPath.js +3 -3
  93. package/sources/file-system/directories/isEmptyDirectory.js +2 -2
  94. package/sources/file-system/directories/isValidDirectoryPath.js +2 -2
  95. package/sources/file-system/fifo-pipes/_fifoPipes.js +3 -3
  96. package/sources/file-system/fifo-pipes/isFIFOPath.js +3 -3
  97. package/sources/file-system/fifo-pipes/isValidFIFOPath.js +2 -2
  98. package/sources/file-system/files/_files.js +4 -4
  99. package/sources/file-system/files/isEmptyFile.js +3 -3
  100. package/sources/file-system/files/isFilePath.js +3 -3
  101. package/sources/file-system/files/isValidFilePath.js +2 -2
  102. package/sources/file-system/paths/_paths.js +2 -2
  103. package/sources/file-system/paths/isValidPath.js +1 -1
  104. package/sources/file-system/sockets/_sockets.js +3 -3
  105. package/sources/file-system/sockets/isSocketPath.js +3 -3
  106. package/sources/file-system/sockets/isValidSocketPath.js +2 -2
  107. package/sources/file-system/symbolic-links/_symbolicLinks.js +3 -3
  108. package/sources/file-system/symbolic-links/isSymbolicLinkPath.js +3 -3
  109. package/sources/file-system/symbolic-links/isValidSymbolicLinkPath.js +2 -2
  110. package/sources/itee-validators.js +4 -4
  111. package/sources/maths/_maths.js +1 -1
  112. package/sources/physics/_physics.js +2 -2
  113. package/sources/physics/temperatures/_temperatures.js +5 -5
  114. package/sources/physics/temperatures/isCelsius.js +2 -2
  115. package/sources/physics/temperatures/isFahrenheit.js +2 -2
  116. package/sources/physics/temperatures/isKelvin.js +2 -2
  117. package/sources/physics/temperatures/isTemperature.js +3 -3
  118. package/.tasks/builds/build.mjs +0 -65
  119. package/.tasks/cleans/clean.mjs +0 -20
  120. package/.tasks/docs/doc.mjs +0 -37
  121. package/.tasks/helps/help.mjs +0 -195
  122. package/.tasks/lints/lint.mjs +0 -33
  123. package/.tasks/patches/patch.mjs +0 -9
  124. package/.tasks/tests/benchmarks/bundle-benchmarks.mjs +0 -33
  125. package/.tasks/tests/benchmarks/run-benchmarks-for-backend.mjs +0 -24
  126. package/.tasks/tests/benchmarks/run-benchmarks-for-frontend.mjs +0 -38
  127. package/.tasks/tests/bundling/check-bundling-from-esm-files-direct.mjs +0 -129
  128. package/.tasks/tests/bundling/check-bundling-from-esm-files-import.mjs +0 -149
  129. package/.tasks/tests/unit-tests/bundle-unit-tests.mjs +0 -33
  130. package/.tasks/tests/unit-tests/run-unit-tests-for-backend.mjs +0 -25
  131. package/.tasks/tests/unit-tests/run-unit-tests-for-frontend.mjs +0 -41
@@ -1,52 +1,41 @@
1
+ import colors from 'ansi-colors'
2
+ import childProcess from 'child_process'
3
+ import log from 'fancy-log'
4
+ import {
5
+ existsSync,
6
+ mkdirSync,
7
+ writeFileSync
8
+ } from 'fs'
1
9
  import {
2
- join,
3
- normalize,
4
10
  basename,
5
11
  dirname,
6
12
  extname,
13
+ join,
7
14
  relative
8
- } from 'path'
15
+ } from 'path'
9
16
  import {
10
- getDirname,
11
- packageInfos
12
- } from '../../_utils.mjs'
13
- import glob from 'glob'
14
- import fs from 'fs'
15
- import log from 'fancy-log'
16
- import colors from 'ansi-colors'
17
- import { getGulpConfigForTask } from '../../../configs/gulp.conf.mjs'
18
- import childProcess from 'child_process'
17
+ nodeModulesDirectory,
18
+ packageName,
19
+ packageSourcesDirectory as sourcesDir,
20
+ packageTestsBenchmarksDirectory as benchesDir
21
+ } from '../../_utils.mjs'
22
+ import { sourcesFiles } from '../../configs/compute-benchmarks.conf.mjs'
19
23
 
20
24
  const {
21
25
  red,
22
26
  green,
23
- blue,
24
- cyan,
25
- yellow,
26
- magenta
27
+ yellow
27
28
  } = colors
28
29
 
30
+ /**
31
+ * @description Will generate benchmarks files from source code against provided alternatives
32
+ */
33
+ const computeBenchmarksTask = ( done ) => {
29
34
 
30
- function computeBenchmarks( done ) {
31
-
32
- const baseDir = getDirname()
33
- const sourcesDir = join( baseDir, 'sources' )
34
- const testsDir = join( baseDir, 'tests' )
35
- const benchesDir = join( testsDir, 'benchmarks' )
36
-
37
- fs.mkdirSync( benchesDir, { recursive: true } )
38
-
39
- const filePathsToIgnore = getGulpConfigForTask( 'compute-benchmarks' )
40
-
41
- const sourcesFiles = glob.sync( join( sourcesDir, '**' ) )
42
- .map( filePath => normalize( filePath ) )
43
- .filter( filePath => {
44
- const fileName = basename( filePath )
45
- const isJsFile = fileName.endsWith( '.js' )
46
- const isNotPrivateFile = !fileName.startsWith( '_' )
47
- const isNotIgnoredFile = !filePathsToIgnore.includes( fileName )
48
- return isJsFile && isNotPrivateFile && isNotIgnoredFile
49
- } )
35
+ if ( !existsSync( benchesDir ) ) {
36
+ log( 'Creating', green( benchesDir ) )
37
+ mkdirSync( benchesDir, { recursive: true } )
38
+ }
50
39
 
51
40
  const benchRootImports = []
52
41
  for ( let sourceFile of sourcesFiles ) {
@@ -65,7 +54,7 @@ function computeBenchmarks( done ) {
65
54
 
66
55
  try {
67
56
 
68
- const jsdocPath = join( baseDir, '/node_modules/jsdoc/jsdoc.js' )
57
+ const jsdocPath = join( nodeModulesDirectory, '/jsdoc/jsdoc.js' )
69
58
  const jsdocOutput = childProcess.execFileSync( 'node', [ jsdocPath, '-X', sourceFile ] ).toString()
70
59
 
71
60
  const classNames = []
@@ -110,7 +99,7 @@ function computeBenchmarks( done ) {
110
99
  } )
111
100
 
112
101
  if ( jsonData.length === 0 ) {
113
- log( yellow( `No usable exports found in [${ sourceFile }]. Ignore it !` ) )
102
+ log( 'Ignoring', yellow( `${ sourceFile }, no usable exports found` ) )
114
103
  continue
115
104
  }
116
105
 
@@ -152,9 +141,8 @@ function computeBenchmarks( done ) {
152
141
  benchSuites += '\n'
153
142
  }
154
143
 
155
- const template = '' + '\n' +
156
- `import Benchmark from 'benchmark'` + '\n' +
157
- `import { Testing } from 'itee-utils'` + '\n' +
144
+ const template = '' +
145
+ `import { Testing } from 'itee-utils/sources/testings/benchmarks.js'` + '\n' +
158
146
  `import * as ${ nsName } from '${ importFilePath }'` + '\n' +
159
147
  '\n' +
160
148
  `${ benchSuites }` +
@@ -168,9 +156,13 @@ function computeBenchmarks( done ) {
168
156
  exports: suitesToExports
169
157
  } )
170
158
 
171
- log( green( `Create ${ benchFilePath }` ) )
172
- fs.mkdirSync( benchDirPath, { recursive: true } )
173
- fs.writeFileSync( benchFilePath, template )
159
+ if ( !existsSync( benchDirPath ) ) {
160
+ log( 'Creating', green( benchDirPath ) )
161
+ mkdirSync( benchDirPath, { recursive: true } )
162
+ }
163
+
164
+ log( 'Creating', green( benchFilePath ) )
165
+ writeFileSync( benchFilePath, template )
174
166
 
175
167
  } catch ( error ) {
176
168
 
@@ -185,9 +177,9 @@ function computeBenchmarks( done ) {
185
177
  for ( let i = 0 ; i < benchRootImports.length ; i++ ) {
186
178
 
187
179
  const currentBench = benchRootImports[ i ]
188
- const exports = currentBench.exports
189
- const imports = exports.join( ', ' )
190
- suites.push( ...exports )
180
+ const namedExports = currentBench.exports
181
+ const imports = namedExports.join( ', ' )
182
+ suites.push( ...namedExports )
191
183
 
192
184
  templateImports += `import {${ imports }} from './${ currentBench.path }'` + '\n'
193
185
 
@@ -203,13 +195,16 @@ function computeBenchmarks( done ) {
203
195
  `\tsuite.run()` + '\n' +
204
196
  `}` + '\n'
205
197
 
206
- const benchesFilePath = join( benchesDir, `${ packageInfos.name }.benchs.js` )
198
+ const benchesFilePath = join( benchesDir, `${ packageName }.benchmarks.js` )
207
199
 
208
- log( green( `Create ${ benchesFilePath }` ) )
209
- fs.writeFileSync( benchesFilePath, benchesTemplate )
200
+ log( 'Creating', green( benchesFilePath ) )
201
+ writeFileSync( benchesFilePath, benchesTemplate )
210
202
 
211
203
  done()
212
204
 
213
205
  }
206
+ computeBenchmarksTask.displayName = 'compute-benchmarks'
207
+ computeBenchmarksTask.description = 'Will generate benchmarks files from source code against provided alternatives.'
208
+ computeBenchmarksTask.flags = null
214
209
 
215
- export { computeBenchmarks }
210
+ export { computeBenchmarksTask }
@@ -0,0 +1,39 @@
1
+ import colors from 'ansi-colors'
2
+ import log from 'fancy-log'
3
+ import { existsSync } from 'fs'
4
+ import { join } from 'path'
5
+ import {
6
+ packageName,
7
+ packageTestsBenchmarksDirectory
8
+ } from '../../_utils.mjs'
9
+
10
+ const {
11
+ red,
12
+ yellow
13
+ } = colors
14
+
15
+ /**
16
+ * @description Will run benchmarks with node
17
+ */
18
+ const runBenchmarksForBackendTask = async ( done ) => {
19
+
20
+ const benchesPath = join( packageTestsBenchmarksDirectory, `/builds/${ packageName }.benchmarks.cjs.js` )
21
+ if ( !existsSync( benchesPath ) ) {
22
+ log( yellow( `${ benchesPath } does not exist, skip backend benchmarks...` ) )
23
+ done()
24
+ return
25
+ }
26
+
27
+ try {
28
+ await import(benchesPath)
29
+ done()
30
+ } catch ( error ) {
31
+ done( red( error ) )
32
+ }
33
+
34
+ }
35
+ runBenchmarksForBackendTask.displayName = 'run-benchmarks-for-backend'
36
+ runBenchmarksForBackendTask.description = 'Will run benchmarks with node'
37
+ runBenchmarksForBackendTask.flags = null
38
+
39
+ export { runBenchmarksForBackendTask }
@@ -0,0 +1,41 @@
1
+ import { startTestRunner } from '@web/test-runner'
2
+ import colors from 'ansi-colors'
3
+ import { default as config } from '../../configs/benchmarks.conf.mjs'
4
+
5
+ const { red } = colors
6
+
7
+ /**
8
+ * @description Will run benchmarks with web-test-runner
9
+ */
10
+ const runBenchmarksForFrontendTask = () => {
11
+ return new Promise( async ( resolve, reject ) => {
12
+
13
+ const testRunner = await startTestRunner( {
14
+ config: config,
15
+ readCliArgs: false,
16
+ readFileConfig: false,
17
+ autoExitProcess: false,
18
+ } )
19
+
20
+ if ( !testRunner ) {
21
+ reject( red( 'Internal test runner error.' ) )
22
+ return
23
+ }
24
+
25
+ // To ensure that testRunner exit event won't be used by other instance of test runner,
26
+ // we need to be sure that current test runner is ended
27
+ testRunner.on( 'finished', () => {
28
+ testRunner.stop()
29
+ } )
30
+
31
+ testRunner.on( 'stopped', () => {
32
+ resolve()
33
+ } )
34
+
35
+ } )
36
+ }
37
+ runBenchmarksForFrontendTask.displayName = 'run-benchmarks-for-frontend'
38
+ runBenchmarksForFrontendTask.description = 'Will run benchmarks with web-test-runner.'
39
+ runBenchmarksForFrontendTask.flags = null
40
+
41
+ export { runBenchmarksForFrontendTask }
@@ -0,0 +1,18 @@
1
+ import { series } from 'gulp'
2
+ import { runBenchmarksForBackendTask } from './run-benchmarks-for-backend.task.mjs'
3
+ import { runBenchmarksForFrontendTask } from './run-benchmarks-for-frontend.task.mjs'
4
+
5
+ /**
6
+ * @method npm run build-test
7
+ * @global
8
+ * @description Will run benchmarks in back and front environments
9
+ */
10
+ const runBenchmarksTestsTask = series(
11
+ runBenchmarksForBackendTask,
12
+ runBenchmarksForFrontendTask,
13
+ )
14
+ runBenchmarksTestsTask.displayName = 'run-benchmarks'
15
+ runBenchmarksTestsTask.description = 'Will run benchmarks in back and front environments.'
16
+ runBenchmarksTestsTask.flags = null
17
+
18
+ export { runBenchmarksTestsTask }
@@ -1,26 +1,24 @@
1
+ import colors from 'ansi-colors'
2
+ import log from 'fancy-log'
3
+ import {
4
+ existsSync,
5
+ mkdirSync,
6
+ readFileSync,
7
+ rmSync,
8
+ writeFileSync
9
+ } from 'fs'
1
10
  import {
2
- join,
3
- normalize,
4
11
  basename,
5
- parse,
6
- dirname,
12
+ join,
7
13
  relative
8
- } from 'path'
14
+ } from 'path'
15
+ import { rollup } from 'rollup'
9
16
  import {
10
- existsSync,
11
- rmSync,
12
- mkdirSync,
13
- writeFileSync,
14
- readFileSync
15
- } from 'fs'
16
- import log from 'fancy-log'
17
- import { nodeResolve } from '@rollup/plugin-node-resolve'
18
- import cleanup from 'rollup-plugin-cleanup'
19
- import { rollup } from 'rollup'
20
- import colors from 'ansi-colors'
21
- import { getDirname } from '../../_utils.mjs'
22
- import { packageInfos } from '../../_utils.mjs'
23
-
17
+ packageBuildsDirectory as buildsDir,
18
+ packageName,
19
+ packageTestsBundlesDirectory as bundlesDir
20
+ } from '../../_utils.mjs'
21
+ import { getRollupConfigurationFor } from '../../configs/build.conf.mjs'
24
22
 
25
23
  const {
26
24
  red,
@@ -28,22 +26,18 @@ const {
28
26
  magenta
29
27
  } = colors
30
28
 
31
- async function checkBundlingFromEsmBuildImport( done ) {
32
-
33
- const baseDir = getDirname()
34
- const buildsDir = join( baseDir, 'builds' )
35
- const buildFilePath = join( buildsDir, `${ packageInfos.name }.esm.js` )
36
- const testsDir = join( baseDir, 'tests' )
37
- const bundlesDir = join( testsDir, 'bundles' )
38
- const outputDir = join( bundlesDir, 'from_build_import' )
39
- const temporaryDir = join( bundlesDir, 'from_build_import', '.tmp' )
40
- const importDir = relative( temporaryDir, buildsDir )
41
- const importFilePath = join( importDir, `${ packageInfos.name }.esm.js` )
29
+ const checkBundlingFromEsmBuildImportTask = async ( done ) => {
42
30
 
31
+ const buildFilePath = join( buildsDir, `${ packageName }.esm.js` )
43
32
  if ( !existsSync( buildFilePath ) ) {
44
33
  done( red( buildFilePath + ' does not exist' ) )
45
34
  }
46
35
 
36
+ const outputDir = join( bundlesDir, 'from_build_import' )
37
+ const temporaryDir = join( bundlesDir, 'from_build_import', '.tmp' )
38
+ const importDir = relative( temporaryDir, buildsDir )
39
+ const importFilePath = join( importDir, `${ packageName }.esm.js` )
40
+
47
41
  if ( existsSync( outputDir ) ) {
48
42
  log( 'Clean up', magenta( outputDir ) )
49
43
  rmSync( outputDir, { recursive: true } )
@@ -81,49 +75,8 @@ async function checkBundlingFromEsmBuildImport( done ) {
81
75
  temporaryFilePaths.push( temporaryFilePath )
82
76
  }
83
77
 
84
- // Bundle each temporary files and check side-effects
85
- const config = {
86
- input: null,
87
- external: [ '' ],
88
- plugins: [
89
- nodeResolve( {
90
- preferBuiltins: true
91
- } ),
92
- cleanup( {
93
- comments: 'all' // else remove __PURE__ declaration... -_-'
94
- } )
95
- ],
96
- onwarn: ( {
97
- loc,
98
- frame,
99
- message
100
- } ) => {
101
-
102
- // Ignore some errors
103
- if ( message.includes( 'Circular dependency' ) ) { return }
104
- if ( message.includes( 'Generated an empty chunk' ) ) { return }
105
-
106
- if ( loc ) {
107
- process.stderr.write( `/!\\ ${ loc.file } (${ loc.line }:${ loc.column }) ${ frame } ${ message }\n` )
108
- } else {
109
- process.stderr.write( `/!\\ ${ message }\n` )
110
- }
111
-
112
- },
113
- treeshake: {
114
- moduleSideEffects: true,
115
- annotations: true,
116
- correctVarValueBeforeDeclaration: true,
117
- propertyReadSideEffects: true,
118
- tryCatchDeoptimization: true,
119
- unknownGlobalSideEffects: true
120
- },
121
- output: {
122
- indent: '\t',
123
- format: 'esm',
124
- file: null
125
- }
126
- }
78
+ // Bundle each temporary files and check side effects
79
+ const config = getRollupConfigurationFor( 'check-bundling-from-esm-build-import' )
127
80
  let fileName, bundleFileName, bundleFilePath
128
81
  for ( const temporaryFilePath of temporaryFilePaths ) {
129
82
 
@@ -154,7 +107,7 @@ async function checkBundlingFromEsmBuildImport( done ) {
154
107
  }
155
108
  }
156
109
 
157
- } catch ( err ) {
110
+ } catch ( error ) {
158
111
  log( red( error.message ) )
159
112
  } finally {
160
113
 
@@ -163,5 +116,8 @@ async function checkBundlingFromEsmBuildImport( done ) {
163
116
  }
164
117
 
165
118
  }
119
+ checkBundlingFromEsmBuildImportTask.displayName = 'check-bundling-from-esm-build-import'
120
+ checkBundlingFromEsmBuildImportTask.description = 'Verify that the project esm build is correctly importable in third party esm files'
121
+ checkBundlingFromEsmBuildImportTask.flags = null
166
122
 
167
- export { checkBundlingFromEsmBuildImport }
123
+ export { checkBundlingFromEsmBuildImportTask }
@@ -0,0 +1,77 @@
1
+ import colors from 'ansi-colors'
2
+ import log from 'fancy-log'
3
+ import {
4
+ existsSync,
5
+ rmSync
6
+ } from 'fs'
7
+ import {
8
+ basename,
9
+ dirname,
10
+ extname,
11
+ join
12
+ } from 'path'
13
+ import { rollup } from 'rollup'
14
+ import {
15
+ packageSourcesDirectory as sourcesDir,
16
+ packageTestsBundlesDirectory as bundlesDir
17
+ } from '../../_utils.mjs'
18
+ import { getRollupConfigurationFor } from '../../configs/build.conf.mjs'
19
+ import { sourcesFiles } from '../../configs/check-bundling.conf.mjs'
20
+
21
+ const {
22
+ red,
23
+ green,
24
+ magenta
25
+ } = colors
26
+
27
+ /**
28
+ * @description In view to detect bundling side effects this task will
29
+ * create intermediary file for each individual export from this package
30
+ * and then create rollup config for each of them and bundle
31
+ * Todo: Check for different target env like next task below this one
32
+ */
33
+ const checkBundlingFromEsmFilesDirectTask = async ( done ) => {
34
+
35
+ const outputDir = join( bundlesDir, 'from_files_direct' )
36
+ if ( existsSync( outputDir ) ) {
37
+ log( 'Clean up', magenta( outputDir ) )
38
+ rmSync( outputDir, { recursive: true } )
39
+ }
40
+
41
+ const config = getRollupConfigurationFor( 'check-bundling-from-esm-files-direct' )
42
+ for ( let sourceFile of sourcesFiles ) {
43
+
44
+ const specificFilePath = sourceFile.replace( sourcesDir, '' )
45
+ const specificDir = dirname( specificFilePath )
46
+ const fileName = basename( sourceFile, extname( sourceFile ) )
47
+
48
+ const bundleFileName = `${ fileName }.bundle.js`
49
+ const bundleFilePath = join( outputDir, specificDir, bundleFileName )
50
+
51
+ config.input = sourceFile
52
+ config.output.file = bundleFilePath
53
+
54
+ try {
55
+
56
+ log( 'Bundling', green( config.output.file ) )
57
+
58
+ const bundle = await rollup( config )
59
+ await bundle.generate( config.output )
60
+ await bundle.write( config.output )
61
+
62
+ } catch ( error ) {
63
+
64
+ log( red( error.message ) )
65
+
66
+ }
67
+
68
+ }
69
+
70
+ done()
71
+
72
+ }
73
+ checkBundlingFromEsmFilesDirectTask.displayName = 'check-bundling-from-esm-files-direct'
74
+ checkBundlingFromEsmFilesDirectTask.description = 'In view to detect bundling side effects this task will create intermediary file for each individual export from this package and then create rollup config for each of them and bundle'
75
+ checkBundlingFromEsmFilesDirectTask.flags = null
76
+
77
+ export { checkBundlingFromEsmFilesDirectTask }
@@ -0,0 +1,95 @@
1
+ import colors from 'ansi-colors'
2
+ import log from 'fancy-log'
3
+ import {
4
+ existsSync,
5
+ mkdirSync,
6
+ rmSync,
7
+ writeFileSync
8
+ } from 'fs'
9
+ import {
10
+ dirname,
11
+ join,
12
+ parse,
13
+ relative
14
+ } from 'path'
15
+ import { rollup } from 'rollup'
16
+ import {
17
+ packageSourcesDirectory as sourcesDir,
18
+ packageTestsBundlesDirectory as bundleDir
19
+ } from '../../_utils.mjs'
20
+ import { getRollupConfigurationFor } from '../../configs/build.conf.mjs'
21
+ import { sourcesFiles } from '../../configs/check-bundling.conf.mjs'
22
+
23
+ const {
24
+ red,
25
+ green,
26
+ magenta
27
+ } = colors
28
+
29
+ const checkBundlingFromEsmFilesImportTask = async ( done ) => {
30
+
31
+ const outputDir = join( bundleDir, 'from_files_import' )
32
+ const temporariesDir = join( outputDir, '.tmp' )
33
+
34
+ if ( existsSync( outputDir ) ) {
35
+ log( 'Clean up', magenta( outputDir ) )
36
+ rmSync( outputDir, { recursive: true } )
37
+ }
38
+
39
+ const config = getRollupConfigurationFor( 'check-bundling-from-esm-files-import' )
40
+ for ( let sourceFile of sourcesFiles ) {
41
+
42
+ const {
43
+ dir: sourceDir,
44
+ base: sourceBase,
45
+ name: sourceName
46
+ } = parse( sourceFile )
47
+ const specificFilePath = sourceFile.replace( sourcesDir, '' )
48
+ const specificDir = dirname( specificFilePath )
49
+
50
+ // Create temp import file per file in package
51
+ const temporaryFileName = `${ sourceName }.import.js`
52
+ const temporaryDir = join( temporariesDir, specificDir )
53
+ const temporaryFile = join( temporaryDir, temporaryFileName )
54
+ const importDir = relative( temporaryDir, sourceDir )
55
+ const importFile = join( importDir, sourceBase )
56
+ const temporaryFileData = `import '${ importFile.replace( /\\/g, '/' ) }'`
57
+
58
+ // Bundle tmp file and check content for side effects
59
+ const bundleFileName = `${ sourceName }.bundle.js`
60
+ const bundleFilePath = join( outputDir, specificDir, bundleFileName )
61
+
62
+ config.input = temporaryFile
63
+ config.output.file = bundleFilePath
64
+
65
+ // create tmp file
66
+ try {
67
+
68
+ mkdirSync( temporaryDir, { recursive: true } )
69
+ writeFileSync( temporaryFile, temporaryFileData )
70
+
71
+ const bundle = await rollup( config )
72
+ const { output } = await bundle.generate( config.output )
73
+
74
+ let code = output[ 0 ].code
75
+ if ( code.length > 1 ) {
76
+ log( red( `[${ specificFilePath }] contain side-effects !` ) )
77
+ await bundle.write( config.output )
78
+ } else {
79
+ log( green( `[${ specificFilePath }] is side-effect free.` ) )
80
+ }
81
+
82
+ } catch ( error ) {
83
+ log( red( error.message ) )
84
+ }
85
+
86
+ }
87
+
88
+ done()
89
+
90
+ }
91
+ checkBundlingFromEsmFilesImportTask.displayName = 'check-bundling-from-esm-files-import'
92
+ checkBundlingFromEsmFilesImportTask.description = 'In view to detect bundling side effects this task will create intermediary file for each individual export from this package and then create rollup config for each of them and bundle'
93
+ checkBundlingFromEsmFilesImportTask.flags = null
94
+
95
+ export { checkBundlingFromEsmFilesImportTask }
@@ -0,0 +1,20 @@
1
+ import { series } from 'gulp'
2
+ import { checkBundlingFromEsmBuildImportTask } from './check-bundling-from-esm-build-import.task.mjs'
3
+ import { checkBundlingFromEsmFilesDirectTask } from './check-bundling-from-esm-files-direct.task.mjs'
4
+ import { checkBundlingFromEsmFilesImportTask } from './check-bundling-from-esm-files-import.task.mjs'
5
+
6
+ /**
7
+ * @description In view to detect bundling side effects this task will
8
+ * create intermediary file for each individual export from this package
9
+ * and then create rollup config for each of them and bundle
10
+ * Todo: Check for differents target env like next task below this one
11
+ */
12
+ const checkBundlingTask = series(
13
+ checkBundlingFromEsmFilesImportTask,
14
+ checkBundlingFromEsmBuildImportTask,
15
+ checkBundlingFromEsmFilesDirectTask
16
+ )
17
+ checkBundlingTask.displayName = 'check-bundling'
18
+ checkBundlingTask.description = 'In view to detect bundling side effects this task will create intermediary file for each individual export and then try to bundle them.'
19
+
20
+ export { checkBundlingTask }
@@ -0,0 +1,18 @@
1
+ import { series } from 'gulp'
2
+ import { runBenchmarksTestsTask } from './benchmarks/run-benchmarks.task.mjs'
3
+ import { runUnitTestsTask } from './unit-tests/run-unit-tests.task.mjs'
4
+
5
+ /**
6
+ * @method npm run test
7
+ * @global
8
+ * @description Will run unit tests and benchmarks for backend (node) and frontend (web-test-runner) environments
9
+ */
10
+ const runTestsTask = series(
11
+ runBenchmarksTestsTask,
12
+ runUnitTestsTask,
13
+ )
14
+ runTestsTask.displayName = 'run-tests'
15
+ runTestsTask.description = 'Will run unit tests and benchmarks for backend (node) and frontend (web-test-runner) environments.'
16
+ runTestsTask.flags = null
17
+
18
+ export { runTestsTask }
@@ -0,0 +1,42 @@
1
+ import colors from 'ansi-colors'
2
+ import log from 'fancy-log'
3
+ import { rollup } from 'rollup'
4
+ import { buildUnitTestsBackendConfig as config } from '../../configs/build-unit-tests-backend.conf.mjs'
5
+
6
+ const {
7
+ red,
8
+ green
9
+ } = colors
10
+
11
+ /**
12
+ * @description Will generate unit test bundles based on provided configs
13
+ */
14
+ const buildUnitTestsBackendTask = async ( done ) => {
15
+
16
+ if ( config === undefined || config === null || config.length === 0 ) {
17
+ done( red( 'Empty configuration!' ) )
18
+ return
19
+ }
20
+
21
+ log( 'Building', green( config.output.file ) )
22
+
23
+ try {
24
+
25
+ const bundle = await rollup( config )
26
+ await bundle.write( config.output )
27
+
28
+ } catch ( error ) {
29
+
30
+ done( red( error.message ) )
31
+ return
32
+
33
+ }
34
+
35
+ done()
36
+
37
+ }
38
+ buildUnitTestsBackendTask.displayName = 'build-unit-tests-backend'
39
+ buildUnitTestsBackendTask.description = 'Will generate unit test bundles based on provided configs'
40
+ buildUnitTestsBackendTask.flags = null
41
+
42
+ export { buildUnitTestsBackendTask }