@jcoreio/toolchain 3.6.3 → 3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcoreio/toolchain",
3
- "version": "3.6.3",
3
+ "version": "3.8.0",
4
4
  "description": "base JS build toolchain",
5
5
  "repository": {
6
6
  "type": "git",
@@ -2,6 +2,7 @@ const { name } = require('../package.json')
2
2
  const dedent = require('dedent-js')
3
3
  const fs = require('../util/projectFs.cjs')
4
4
  const JSON5 = require('json5')
5
+ const getPluginsArraySync = require('../util/getPluginsArraySync.cjs')
5
6
 
6
7
  async function getRootEslintConfig() {
7
8
  if (await fs.pathExists('.eslintrc.json')) {
@@ -30,6 +31,21 @@ module.exports = [
30
31
  }
31
32
  }
32
33
  `,
34
+ 'toolchain.config.cjs': async (existing) => {
35
+ if (existing) return existing
36
+ return dedent`
37
+ /* eslint-env node, es2018 */
38
+ module.exports = {
39
+ // scripts: {
40
+ // pretest: 'docker compose up -d',
41
+ // jsExample: {
42
+ // description: 'example of running a JS script',
43
+ // run: async (args = []) => console.log('TEST', ...args),
44
+ // },
45
+ // }
46
+ }
47
+ `
48
+ },
33
49
  }
34
50
  for (const file of [
35
51
  'githooks.cjs',
@@ -45,6 +61,30 @@ module.exports = [
45
61
 
46
62
  `
47
63
  }
64
+ const tasks = await getPluginsArraySync('vscodeTasks')
65
+ const launch = await getPluginsArraySync('vscodeLaunch')
66
+
67
+ if (tasks) {
68
+ files['.vscode/tasks.json'] = JSON.stringify(
69
+ {
70
+ version: '2.0.0',
71
+ tasks,
72
+ },
73
+ null,
74
+ 2
75
+ )
76
+ }
77
+ if (launch) {
78
+ files['.vscode/launch.json'] = JSON.stringify(
79
+ {
80
+ version: '0.2.0',
81
+ configurations: launch,
82
+ },
83
+ null,
84
+ 2
85
+ )
86
+ }
87
+
48
88
  return files
49
89
  },
50
90
  ]
package/scripts/check.cjs CHANGED
@@ -8,7 +8,7 @@ const fs = require('../util/projectFs.cjs')
8
8
  exports.run = async function check(args = []) {
9
9
  await require('../scripts/runPrettier.cjs').prettierCheck(args)
10
10
  await require('../scripts/runEslint.cjs').eslintCheck(args)
11
- const isTest = Boolean(process.env.JCOREIO_TOOLCHAIN_TEST)
11
+ const isTest = Boolean(process.env.JCOREIO_TOOLCHAIN_SELF_TEST)
12
12
  if (devDependencies['flow-bin'] && (await fs.pathExists('.flowconfig'))) {
13
13
  await execa('flow', isTest ? ['check'] : [])
14
14
  }
package/scripts/init.cjs CHANGED
@@ -63,7 +63,7 @@ async function init(args = []) {
63
63
  selectedToolchains.push(`${name}-esnext`)
64
64
  }
65
65
 
66
- const isTest = Boolean(process.env.JCOREIO_TOOLCHAIN_TEST)
66
+ const isTest = Boolean(process.env.JCOREIO_TOOLCHAIN_SELF_TEST)
67
67
 
68
68
  await execa('tc', ['preinstall'])
69
69
  await execa('pnpm', [
@@ -133,7 +133,7 @@ async function migrateProjectPackageJson() {
133
133
  )
134
134
  if (isEmpty(packageJson.config)) delete packageJson.config
135
135
 
136
- const isTest = Boolean(process.env.JCOREIO_TOOLCHAIN_TEST)
136
+ const isTest = Boolean(process.env.JCOREIO_TOOLCHAIN_SELF_TEST)
137
137
 
138
138
  for (const section in toolchainManaged) {
139
139
  if (!section.endsWith('ependencies')) continue
@@ -4,7 +4,9 @@ exports.run = async function (args = []) {
4
4
  const { scripts } = require('./toolchain.cjs')
5
5
  await execa('tc', ['check'])
6
6
  if (scripts.coverage) await execa('tc', ['coverage'])
7
+ if (scripts['test:esm']) await execa('tc', ['test:esm'])
7
8
  await execa('tc', ['build'])
9
+ await execa('tc', ['build:smoke-test'])
8
10
  }
9
11
 
10
12
  exports.description = 'run check, coverage, and build'
@@ -0,0 +1,26 @@
1
+ const getModules = require('../util/getModules.cjs')
2
+ const execa = require('../util/execa.cjs')
3
+ const path = require('path')
4
+
5
+ exports.run = async function smokeTestBuild() {
6
+ const { cjs, esm } = await getModules('dist/package.json')
7
+
8
+ function relpath(file) {
9
+ const result = path.relative(process.cwd(), file)
10
+ return result.startsWith('.') ? result : `./${result}`
11
+ }
12
+
13
+ for (const file of cjs) {
14
+ await execa('node', ['-e', `require(${JSON.stringify(relpath(file))})`])
15
+ }
16
+ for (const file of esm) {
17
+ await execa('node', [
18
+ '--input-type',
19
+ 'module',
20
+ '-e',
21
+ `import ${JSON.stringify(relpath(file))}`,
22
+ ])
23
+ }
24
+ }
25
+
26
+ exports.description = 'smoke test that build output can be required/imported'
@@ -9,6 +9,7 @@ const execa = require('../util/execa.cjs')
9
9
  const scripts = {
10
10
  migrate: require('./migrate.cjs'),
11
11
  build: require('./build.cjs'),
12
+ 'build:smoke-test': require('./smokeTestBuild.cjs'),
12
13
  check: require('./check.cjs'),
13
14
  clean: require('./clean.cjs'),
14
15
  format: require('./format.cjs'),
@@ -9,7 +9,7 @@ async function upgrade([version] = []) {
9
9
  const toolchains = Object.keys(devDependencies).filter((pkg) =>
10
10
  pkg.startsWith(`${name}-`)
11
11
  )
12
- const isTest = Boolean(process.env.JCOREIO_TOOLCHAIN_TEST)
12
+ const isTest = Boolean(process.env.JCOREIO_TOOLCHAIN_SELF_TEST)
13
13
 
14
14
  if (!isTest && !version) {
15
15
  version = (
@@ -0,0 +1,72 @@
1
+ const fs = require('./projectFs.cjs')
2
+ const glob = require('./glob.cjs')
3
+ const path = require('path')
4
+
5
+ module.exports = async function getModules(packageJsonFile) {
6
+ const cjs = new Set()
7
+ const esm = new Set()
8
+
9
+ const {
10
+ type = 'commonjs',
11
+ main,
12
+ module,
13
+ bin,
14
+ exports,
15
+ } = await fs.readJson(packageJsonFile)
16
+
17
+ const defaultType = type
18
+ function checkFile(
19
+ file,
20
+ type = file
21
+ ? /\.cjs$/.test(file)
22
+ ? 'commonjs'
23
+ : /\.mjs$/.test(file)
24
+ ? 'module'
25
+ : /\.js$/.test(file)
26
+ ? defaultType
27
+ : undefined
28
+ : undefined
29
+ ) {
30
+ if (!file) return
31
+ if (type === 'commonjs') cjs.add(file)
32
+ else if (type === 'module') esm.add(file)
33
+ }
34
+
35
+ checkFile(main)
36
+ checkFile(module)
37
+ if (typeof bin === 'string') checkFile(bin)
38
+ else if (bin instanceof Object) {
39
+ for (const file of Object.values(bin)) checkFile(file)
40
+ }
41
+
42
+ async function checkExport(exp, type) {
43
+ if (typeof exp === 'string') {
44
+ if (exp.includes('*')) {
45
+ const files = await glob(exp.replace('*', '**'), {
46
+ cwd: path.dirname(packageJsonFile),
47
+ })
48
+ for (const file of files) checkFile(file, type)
49
+ } else {
50
+ checkFile(exp, type)
51
+ }
52
+ } else if (exp instanceof Object) {
53
+ for (const [key, value] of Object.entries(exp)) {
54
+ await checkExport(
55
+ value,
56
+ type ||
57
+ (key === 'require'
58
+ ? 'commonjs'
59
+ : key === 'import'
60
+ ? 'module'
61
+ : undefined)
62
+ )
63
+ }
64
+ }
65
+ }
66
+
67
+ await checkExport(exports)
68
+
69
+ const resolvePath = (f) => path.resolve(path.dirname(packageJsonFile), f)
70
+
71
+ return { cjs: [...cjs].map(resolvePath), esm: [...esm].map(resolvePath) }
72
+ }
@@ -1,5 +1,5 @@
1
1
  module.exports =
2
- !process.env.JCOREIO_TOOLCHAIN_TEST &&
2
+ !process.env.JCOREIO_TOOLCHAIN_SELF_TEST &&
3
3
  process.stdout.isTTY &&
4
4
  process.env.TERM !== 'dumb' &&
5
5
  !('CI' in process.env)