@jcoreio/toolchain 1.0.0-beta.10 → 1.0.0-beta.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.
package/bin/commitizen ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
4
+
5
+ exec $(node "$basedir/resolveBin.cjs" commitizen) "$@"
package/bin/commitlint ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
4
+
5
+ exec $(node "$basedir/resolveBin.cjs" @commitlint/cli commitlint) "$@"
package/bin/cz ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
4
+
5
+ exec $(node "$basedir/resolveBin.cjs" commitizen cz) "$@"
package/bin/git-cz ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
4
+
5
+ exec $(node "$basedir/resolveBin.cjs" commitizen git-cz) "$@"
File without changes
package/commitizen.cjs ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('cz-conventional-changelog')
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+ extends: [require.resolve('@commitlint/config-conventional')],
3
+ rules: {
4
+ 'scope-case': [0, 'always', ['lowerCase']],
5
+ 'subject-case': [
6
+ 0,
7
+ 'never',
8
+ ['upper-case', 'camel-case', 'pascal-case', 'snake-case'],
9
+ ],
10
+ },
11
+ }
@@ -2,7 +2,7 @@ const Path = require('path')
2
2
  const { findGitDir } = require('../util/findUps.cjs')
3
3
  const execa = require('../util/execa.cjs')
4
4
 
5
- module.exports = async function runHook(hookName) {
5
+ module.exports = async function runHook(hook) {
6
6
  try {
7
7
  const gitDir = findGitDir()
8
8
  if (!gitDir) {
@@ -16,13 +16,9 @@ module.exports = async function runHook(hookName) {
16
16
  } catch (error) {
17
17
  hooks = require('../githooks.cjs')
18
18
  }
19
- const hook = hooks[hookName]
20
- if (!hook) return
21
19
 
22
- if (typeof hook === 'function') {
23
- await hook()
24
- } else if (hook) {
25
- await execa(hook, {
20
+ if (hooks[hook]) {
21
+ await execa(hooks[hook], {
26
22
  cwd: projDir,
27
23
  shell: true,
28
24
  })
package/githooks.cjs CHANGED
@@ -1,3 +1,5 @@
1
1
  module.exports = {
2
+ 'prepare-commit-msg': `grep -qE '^[^#]' .git/COMMIT_EDITMSG || (exec < /dev/tty && cz --hook || true)`,
2
3
  'pre-commit': 'lint-staged',
4
+ 'commit-msg': `commitlint -e`,
3
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcoreio/toolchain",
3
- "version": "1.0.0-beta.10",
3
+ "version": "1.0.0-beta.2",
4
4
  "description": "base JS build toolchain",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,10 +14,18 @@
14
14
  },
15
15
  "homepage": "https://github.com/jcoreio/toolchains/tree/beta/packages/base",
16
16
  "dependencies": {
17
+ "@commitlint/cli": "^15.0.0",
18
+ "@commitlint/config-conventional": "^15.0.0",
19
+ "@semantic-release/commit-analyzer": "^9.0.2",
20
+ "@semantic-release/github": "^8.0.4",
21
+ "@semantic-release/npm": "^10.0.4",
22
+ "@semantic-release/release-notes-generator": "^10.0.3",
17
23
  "chalk": "^4.0.0",
24
+ "commitizen": "^4.2.4",
25
+ "cz-conventional-changelog": "^3.3.0",
18
26
  "dedent-js": "^1.0.1",
19
- "eslint": "^8.43.0",
20
- "eslint-config-prettier": "^8.8.0",
27
+ "eslint": "^8.5.0",
28
+ "eslint-config-prettier": "^8.3.0",
21
29
  "execa": "^5.0.0",
22
30
  "find-up": "^5.0.0",
23
31
  "fs-extra": "^10.0.0",
@@ -27,23 +35,21 @@
27
35
  "open": "^8.4.0",
28
36
  "prettier": "^2.5.1",
29
37
  "resolve-bin": "^1.0.0",
30
- "semver": "^7.5.3",
31
- "toposort": "^2.0.2",
32
- "zod": "^3.21.4"
38
+ "semantic-release": "^21.0.5",
39
+ "toposort": "^2.0.2"
33
40
  },
34
- "toolchainManaged": {
35
- "engines": {
36
- "node": ">=16"
37
- },
38
- "packageManager": "pnpm@8.3.1",
39
- "devDependencies": {
40
- "eslint": "*"
41
- }
41
+ "peerDependencies": {
42
+ "eslint": "^8.0.0"
42
43
  },
43
44
  "bin": {
45
+ "commitizen": "./bin/commitizen",
46
+ "commitlint": "./bin/commitlint",
47
+ "cz": "./bin/cz",
44
48
  "eslint": "./bin/eslint",
49
+ "git-cz": "./bin/git-cz",
45
50
  "lint-staged": "./bin/lint-staged",
46
51
  "prettier": "./bin/prettier",
52
+ "semantic-release": "./bin/semantic-release",
47
53
  "tc": "./scripts/toolchain.cjs",
48
54
  "toolchain": "./scripts/toolchain.cjs"
49
55
  },
@@ -30,8 +30,15 @@ module.exports = [
30
30
  }
31
31
  }
32
32
  `,
33
+ 'release.config.js': dedent`
34
+ /* eslint-env node, es2018 */
35
+ module.exports = {
36
+ extends: [require.resolve('${name}/release.config.cjs')],
37
+ }
38
+ `,
33
39
  }
34
40
  for (const file of [
41
+ 'commitlint.config.cjs',
35
42
  'githooks.cjs',
36
43
  'lint-staged.config.cjs',
37
44
  'prettier.config.cjs',
@@ -0,0 +1,16 @@
1
+ const { projectDir } = require('./util/findUps.cjs')
2
+ const path = require('path')
3
+
4
+ module.exports = {
5
+ plugins: [
6
+ require.resolve('@semantic-release/commit-analyzer'),
7
+ require.resolve('@semantic-release/release-notes-generator'),
8
+ [
9
+ require.resolve('@semantic-release/npm'),
10
+ {
11
+ pkgRoot: path.join(projectDir, 'dist'),
12
+ },
13
+ ],
14
+ require.resolve('@semantic-release/github'),
15
+ ],
16
+ }
@@ -1,28 +1,13 @@
1
1
  const fs = require('../../util/projectFs.cjs')
2
- const path = require('path')
3
- const getPluginsObjectAsync = require('../../util/getPluginsObjectAsync.cjs')
4
- const { name } = require('../../package.json')
2
+ const getPluginsObject = require('../../util/getPluginsObject.cjs')
5
3
 
6
4
  async function bootstrapConfigFiles() {
7
- const files = await getPluginsObjectAsync('getConfigFiles')
5
+ const files = await getPluginsObject('getConfigFiles')
8
6
  for (const file in files) {
9
7
  const value = files[file]
10
- let content, overwrite
11
- if (typeof value === 'function') {
12
- const prev = await fs.readFile(file, 'utf8').catch(() => undefined)
13
- content = await value(prev)
14
- overwrite = content !== prev
15
- } else {
16
- content = typeof value === 'string' ? value : value.content
17
- overwrite = typeof value === 'string' ? false : value.overwrite
18
- }
19
- if (
20
- overwrite === true ||
21
- !(await fs.pathExists(file)) ||
22
- (content.includes(name) &&
23
- !(await fs.readFile(file, 'utf8')).includes(name))
24
- ) {
25
- await fs.mkdirs(path.dirname(file))
8
+ const content = typeof value === 'string' ? value : value.content
9
+ const overwrite = typeof value === 'string' ? false : value.overwrite
10
+ if (overwrite || !(await fs.pathExists(file))) {
26
11
  await fs.writeFile(file, content, 'utf8')
27
12
  // eslint-disable-next-line no-console
28
13
  console.error(`wrote ${file}`)
@@ -1,10 +1,8 @@
1
- const { toolchainManaged } = require('../../util/findUps.cjs')
1
+ const { name, peerDependencies: basePeerDeps } = require('../../package.json')
2
+ const { projectDir, toolchainPackages } = require('../../util/findUps.cjs')
2
3
  const getPluginsAsyncFunction = require('../../util/getPluginsAsyncFunction.cjs')
3
4
  const fs = require('../../util/projectFs.cjs')
4
5
  const sortDeps = require('../../util/sortDeps.cjs')
5
- const semver = require('semver')
6
- const isEmpty = require('lodash/isEmpty')
7
- const pick = require('lodash/pick')
8
6
 
9
7
  async function bootstrapProjectPackageJson() {
10
8
  const { merge, unset } = require('lodash')
@@ -13,54 +11,29 @@ async function bootstrapProjectPackageJson() {
13
11
  const devDependencies =
14
12
  packageJson.devDependencies || (packageJson.devDependencies = {})
15
13
 
16
- await getPluginsAsyncFunction('bootstrapProjectPackageJson')(packageJson)
14
+ const peerDependencies = { ...basePeerDeps }
15
+ for (const pkg of toolchainPackages) {
16
+ Object.assign(
17
+ peerDependencies,
18
+ require(require.resolve(`${pkg}/package.json`, { paths: [projectDir] }))
19
+ .peerDependencies
20
+ )
21
+ }
17
22
 
18
23
  for (const path of [
19
- 'commitlint',
20
- 'config.commitizen',
21
- 'config.eslint',
22
- 'config.lint',
23
- 'config.mocha',
24
- 'config.prettier',
25
- 'eslintConfig',
26
24
  'exports',
25
+ 'eslintConfig',
27
26
  'files',
28
27
  'husky',
29
- 'husky',
30
- 'lint-staged',
31
28
  'main',
32
29
  'module',
33
- 'nyc',
34
- 'prettier',
35
30
  'renovate',
36
- 'scripts.build:cjs',
37
- 'scripts.build:js',
38
- 'scripts.build:mjs',
39
- 'scripts.build:types',
40
- 'scripts.build',
41
- 'scripts.clean',
42
- 'scripts.codecov',
43
- 'scripts.coverage',
44
- 'scripts.commitmsg',
45
- 'scripts.flow:coverage',
46
- 'scripts.flow:watch',
47
- 'scripts.flow',
48
- 'scripts.lint:fix',
49
- 'scripts.lint:watch',
50
- 'scripts.lint',
51
- 'scripts.open:coverage',
52
- 'scripts.precommit',
53
- 'scripts.prepublishOnly',
54
- 'scripts.prepush',
55
- 'scripts.prettier:check',
56
- 'scripts.prettier',
57
- 'scripts.semantic-release',
58
- 'scripts.test:debug',
59
- 'scripts.test:watch',
60
- 'scripts.test',
61
- 'scripts.travis-deploy-once',
62
- 'scripts.tsc:wath',
63
- 'scripts.tsc',
31
+ 'prettier',
32
+ 'commitlint',
33
+ 'lint-staged',
34
+ 'nyc',
35
+ 'husky',
36
+ 'config.mocha',
64
37
  ]) {
65
38
  unset(packageJson, path)
66
39
  }
@@ -68,45 +41,31 @@ async function bootstrapProjectPackageJson() {
68
41
  delete devDependencies[dep]
69
42
  }
70
43
 
71
- merge(
72
- packageJson,
73
- {
74
- version: '0.0.0-development',
75
- sideEffects: false,
76
- scripts: {
77
- tc: 'toolchain',
78
- toolchain: 'toolchain',
79
- test: 'toolchain test',
80
- prepublishOnly:
81
- 'echo This package is meant to be published by semantic-release from the dist build directory. && exit 1',
82
- },
44
+ merge(packageJson, {
45
+ version: '0.0.0-development',
46
+ sideEffects: false,
47
+ scripts: {
48
+ tc: 'toolchain',
49
+ toolchain: 'toolchain',
50
+ test: 'toolchain test',
51
+ prepublishOnly:
52
+ 'echo This package is meant to be published by semantic-release from the dist build directory. && exit 1',
53
+ },
54
+ config: {
55
+ commitizen: { path: `${name}/commitizen.cjs` },
83
56
  },
84
- pick(toolchainManaged, 'engines', 'packageManager'),
85
- pick(packageJson, 'engines')
86
- )
87
- if (isEmpty(packageJson.config)) delete packageJson.config
57
+ })
88
58
 
89
- for (const section in toolchainManaged) {
90
- if (!section.endsWith('ependencies')) continue
91
- const managedSection = toolchainManaged[section]
92
- const pkgSectionName = section.replace(/^optionalD/, 'd')
93
- let pkgSection = packageJson[pkgSectionName]
94
- if (!pkgSection) {
95
- if (/^optional/.test(section)) continue
96
- pkgSection = packageJson[pkgSectionName] = {}
97
- }
98
- for (const dep in managedSection) {
99
- if (/^optional/.test(section) && !pkgSection[dep]) continue
100
- const versionRange = managedSection[dep]
101
- if (
102
- !pkgSection[dep] ||
103
- !semver.satisfies(semver.minVersion(pkgSection[dep]), versionRange)
104
- ) {
105
- pkgSection[dep] = versionRange
106
- }
59
+ if (peerDependencies) {
60
+ for (const dep in peerDependencies) {
61
+ const version = peerDependencies[dep]
62
+ if (version.startsWith('workspace') || version === '*') continue
63
+ packageJson.devDependencies[dep] = version
107
64
  }
108
65
  }
109
66
 
67
+ await getPluginsAsyncFunction('bootstrapProjectPackageJson')(packageJson)
68
+
110
69
  sortDeps(packageJson)
111
70
 
112
71
  await fs.writeJson('package.json', packageJson, { spaces: 2 })
@@ -89,17 +89,19 @@ module.exports = [
89
89
  'babel-types',
90
90
  'babylon',
91
91
  'codecov',
92
- 'commitizen',
93
- 'cz-conventional-changelog',
94
92
  'coveralls',
93
+ 'eslint-plugin-flowtype',
94
+ 'eslint-plugin-prettier',
95
+ 'eslint-plugin-react',
95
96
  'eslint-watch',
97
+ 'eslint',
96
98
  'flow-copy-source',
97
99
  'flow-watch',
98
100
  'husky',
99
101
  'isparta',
100
102
  'istanbul',
101
- 'jsdom-global',
102
103
  'lint-staged',
104
+ 'mocha',
103
105
  'nyc',
104
106
  'prettier-eslint',
105
107
  'prettier',
@@ -1,26 +1,24 @@
1
1
  module.exports = [
2
+ '.babelrc.cjs',
2
3
  '.babelrc.js',
3
4
  '.babelrc.json',
4
5
  '.babelrc.mjs',
5
6
  '.babelrc',
6
- 'babel.config.cjs',
7
- 'babel.config.js',
8
- 'babel.config.json',
9
- 'babel.config.mjs',
10
7
  '.commitlintrc.js',
11
8
  '.commitlintrc.json',
12
9
  '.commitlintrc.yml',
13
- 'commitlint.config.js',
14
10
  '.eslintignore',
11
+ '.github/renovate.json',
12
+ '.github/renovate.json5',
15
13
  '.gitignore',
14
+ '.gitlab/renovate.json',
15
+ '.gitlab/renovate.json5',
16
16
  '.lintstagedrc',
17
- 'lint-staged.config.js',
18
17
  '.npmignore',
19
18
  '.nycrc.json',
20
19
  '.nycrc.yaml',
21
20
  '.nycrc.yml',
22
21
  '.nycrc',
23
- 'nyc.config.js',
24
22
  '.prettierrc.cjs',
25
23
  '.prettierrc.js',
26
24
  '.prettierrc.json',
@@ -29,17 +27,24 @@ module.exports = [
29
27
  '.prettierrc.yaml',
30
28
  '.prettierrc.yml',
31
29
  '.prettierrc',
32
- 'prettier.config.js',
33
- 'package-lock.json',
34
- '.github/renovate.json',
35
- '.github/renovate.json5',
36
- '.gitlab/renovate.json',
37
- '.gitlab/renovate.json5',
38
30
  '.renovaterc.json',
39
31
  '.renovaterc',
32
+ '.travis.yml',
33
+ 'babel.config.cjs',
34
+ 'babel.config.js',
35
+ 'babel.config.json',
36
+ 'babel.config.mjs',
37
+ 'commitlint.config.cjs',
38
+ 'commitlint.config.js',
39
+ 'lint-staged.config.cjs',
40
+ 'lint-staged.config.js',
41
+ 'nyc.config.cjs',
42
+ 'nyc.config.js',
43
+ 'package-lock.json',
44
+ 'prettier.config.cjs',
45
+ 'prettier.config.js',
40
46
  'renovate.json',
41
47
  'renovate.json5',
42
48
  'solano.yml',
43
- '.travis.yml',
44
49
  'yarn.lock',
45
50
  ]
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+
3
+ const execa = require('../../util/execa.cjs')
4
+ const Path = require('path')
5
+ const dedent = require('dedent-js')
6
+ const { findGitDir } = require('../../util/findUps.cjs')
7
+
8
+ async function installGitHooks() {
9
+ const gitDir = findGitDir()
10
+ if (!gitDir) {
11
+ // eslint-disable-next-line no-console
12
+ console.warn(dedent`
13
+ .git directory not found!
14
+ git hooks could not be installed.
15
+ after you run \`git init\`, try \`pnpm exec install-git-hooks\`.
16
+ `)
17
+ } else {
18
+ await execa('git', [
19
+ 'config',
20
+ 'core.hooksPath',
21
+ Path.relative(
22
+ Path.dirname(gitDir),
23
+ Path.resolve(__dirname, '..', '..', 'githooks')
24
+ ),
25
+ ])
26
+ // eslint-disable-next-line no-console
27
+ console.log('successfully installed git hooks!')
28
+ }
29
+ }
30
+
31
+ module.exports = installGitHooks
@@ -5,21 +5,17 @@ const getPluginsAsyncFunction = require('../util/getPluginsAsyncFunction.cjs')
5
5
 
6
6
  async function bootstrap(args = []) {
7
7
  const execa = require('../util/execa.cjs')
8
- const installGitHooks = require('./install-git-hooks.cjs')
8
+ const installGitHooks = require('./bootstrap/installGitHooks.cjs')
9
9
  const bootstrapProjectPackageJson = require('./bootstrap/bootstrapProjectPackageJson.cjs')
10
10
  const bootstrapEslintConfigs = require('./bootstrap/bootstrapEslintConfigs.cjs')
11
11
  const bootstrapConfigFiles = require('./bootstrap/bootstrapConfigFiles.cjs')
12
12
  const bootstrapMoveTypeDefs = require('./bootstrap/bootstrapMoveTypeDefs.cjs')
13
13
  const bootstrapGitignore = require('./bootstrap/bootstrapGitignore.cjs')
14
14
  const bootstrapRemoveFiles = require('./bootstrap/bootstrapRemoveFiles.cjs')
15
- const hasYarnOrNpmLockfile = require('../util/hasYarnOrNpmLockfile.cjs')
16
15
 
17
16
  await execa('git', ['init'])
18
- await installGitHooks.run()
17
+ await installGitHooks()
19
18
  await bootstrapProjectPackageJson()
20
- if (await hasYarnOrNpmLockfile()) {
21
- await execa('pnpm', ['import'])
22
- }
23
19
  await Promise.all(
24
20
  bootstrapRemoveFiles.map(async (file) => {
25
21
  const exists = await fs.pathExists(file)
package/scripts/check.cjs CHANGED
@@ -8,9 +8,8 @@ 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)
12
11
  if (devDependencies['flow-bin'] && (await fs.pathExists('.flowconfig'))) {
13
- await execa('flow', isTest ? ['check'] : [])
12
+ await execa('flow')
14
13
  }
15
14
  if (devDependencies['typescript'] && (await fs.pathExists('tsconfig.json'))) {
16
15
  await execa('tsc', ['--noEmit'])
@@ -0,0 +1,12 @@
1
+ const getPlugins = require('../util/getPlugins.cjs')
2
+ const getPluginsAsyncFunction = require('../util/getPluginsAsyncFunction.cjs')
3
+
4
+ exports.run = async function (args = []) {
5
+ if (!getPlugins('coverage').length) {
6
+ throw new Error(
7
+ 'missing test toolchain, install @jcoreio/toolchain-mocha (there may be alternatives in the future)'
8
+ )
9
+ }
10
+ await getPluginsAsyncFunction('coverage')(args)
11
+ }
12
+ exports.description = 'run tests with code coverage'
package/scripts/init.cjs CHANGED
@@ -3,29 +3,23 @@
3
3
  const { packageJson } = require('../util/findUps.cjs')
4
4
  const preinstall = require('./preinstall.cjs')
5
5
  const execa = require('../util/execa.cjs')
6
- const hasTSFiles = require('../util/hasTSFiles.cjs')
7
6
 
8
7
  async function init(args = []) {
9
8
  const { dependencies = {}, devDependencies = {} } = packageJson
10
9
  const toolchains = []
11
10
  const isBabel =
12
11
  devDependencies['@babel/core'] != null ||
13
- devDependencies['babel-core'] != null ||
14
- devDependencies['@jcoreio/toolchain-esnext'] != null
15
- const isTS = await hasTSFiles()
12
+ devDependencies['babel-core'] != null
13
+ const isTS = isBabel && devDependencies.typescript != null
16
14
  const isFlow = isBabel && devDependencies['flow-bin'] != null
17
15
  const isReact = dependencies.react != null || devDependencies.react != null
18
16
  const isMocha = devDependencies['mocha'] != null
19
- const isCircle = true // might be false someday
20
- const isSemanticRelease = devDependencies['semantic-release'] != null
21
17
 
22
18
  if (isMocha) toolchains.push('@jcoreio/toolchain-mocha')
23
19
  if (isBabel) toolchains.push('@jcoreio/toolchain-esnext')
24
20
  if (isFlow) toolchains.push('@jcoreio/toolchain-flow')
25
21
  if (isTS) toolchains.push('@jcoreio/toolchain-typescript')
26
22
  if (isReact) toolchains.push('@jcoreio/toolchain-react')
27
- if (isCircle) toolchains.push('@jcoreio/toolchain-circle')
28
- if (isSemanticRelease) toolchains.push('@jcoreio/toolchain-semantic-release')
29
23
 
30
24
  const isTest = Boolean(process.env.JCOREIO_TOOLCHAIN_TEST)
31
25
 
@@ -2,6 +2,7 @@ module.exports = [
2
2
  '.babelrc',
3
3
  '.babelrc.json',
4
4
  '.babelrc.js',
5
+ '.babelrc.cjs',
5
6
  '.babelrc.mjs',
6
7
  'babel.config.json',
7
8
  'babel.config.js',
@@ -16,21 +17,25 @@ module.exports = [
16
17
  '.prettierrc.js',
17
18
  '.prettierrc.cjs',
18
19
  'prettier.config.js',
20
+ 'prettier.config.cjs',
19
21
  'package-lock.json',
20
22
  '.npmignore',
21
23
  '.gitignore',
22
24
  '.eslintignore',
23
25
  'commitlint.config.js',
26
+ 'commitlint.config.cjs',
24
27
  '.commitlintrc.js',
25
28
  '.commitlintrc.json',
26
29
  '.commitlintrc.yml',
27
30
  '.lintstagedrc',
28
31
  'lint-staged.config.js',
32
+ 'lint-staged.config.cjs',
29
33
  '.nycrc',
30
34
  '.nycrc.json',
31
35
  '.nycrc.yaml',
32
36
  '.nycrc.yml',
33
37
  'nyc.config.js',
38
+ 'nyc.config.cjs',
34
39
  '.github/renovate.json',
35
40
  '.github/renovate.json5',
36
41
  '.gitlab/renovate.json',
@@ -4,12 +4,7 @@ const fs = require('../util/projectFs.cjs')
4
4
 
5
5
  async function preinstall(args = []) {
6
6
  const preinstallUpdateProjectPackageJson = require('./preinstall/preinstallUpdateProjectPackageJson.cjs')
7
- const execa = require('../util/execa.cjs')
8
- const hasYarnOrNpmLockfile = require('../util/hasYarnOrNpmLockfile.cjs')
9
7
 
10
- if (await hasYarnOrNpmLockfile()) {
11
- await execa('pnpm', ['import'])
12
- }
13
8
  await Promise.all(
14
9
  require('./preinstall/preinstallRemoveFiles.cjs').map(async (file) => {
15
10
  const exists = await fs.pathExists(file)
@@ -1,10 +1,10 @@
1
1
  const check = require('./check.cjs')
2
+ const coverage = require('./coverage.cjs')
2
3
  const build = require('./build.cjs')
3
4
 
4
5
  exports.run = async function (args = []) {
5
6
  await check.run()
6
- const { scripts } = require('./toolchain.cjs')
7
- if (scripts.coverage) await scripts.coverage.run()
7
+ await coverage.run()
8
8
  await build.run()
9
9
  }
10
10
 
@@ -0,0 +1,12 @@
1
+ const getPlugins = require('../util/getPlugins.cjs')
2
+ const getPluginsAsyncFunction = require('../util/getPluginsAsyncFunction.cjs')
3
+
4
+ exports.run = async function (args = []) {
5
+ if (!getPlugins('test').length) {
6
+ throw new Error(
7
+ 'missing test toolchain, install @jcoreio/toolchain-mocha (there may be alternatives in the future)'
8
+ )
9
+ }
10
+ await getPluginsAsyncFunction('test')(args)
11
+ }
12
+ exports.description = 'run tests'
@@ -2,13 +2,13 @@
2
2
 
3
3
  const { name, version } = require('../package.json')
4
4
  const chalk = require('chalk')
5
- const getPluginsObjectSync = require('../util/getPluginsObjectSync.cjs')
6
5
 
7
6
  const scripts = {
8
7
  bootstrap: require('./bootstrap.cjs'),
9
8
  build: require('./build.cjs'),
10
9
  check: require('./check.cjs'),
11
10
  clean: require('./clean.cjs'),
11
+ coverage: require('./coverage.cjs'),
12
12
  format: require('./format.cjs'),
13
13
  init: require('./init.cjs'),
14
14
  preinstall: require('./preinstall.cjs'),
@@ -16,6 +16,7 @@ const scripts = {
16
16
  'lint:fix': require('./lint-fix.cjs'),
17
17
  'open:coverage': require('./open-coverage.cjs'),
18
18
  prepublish: require('./prepublish.cjs'),
19
+ test: require('./test.cjs'),
19
20
  version: {
20
21
  description: `print version of ${name}`,
21
22
  run: () => {
@@ -23,8 +24,6 @@ const scripts = {
23
24
  console.log(`${name}@${version}`)
24
25
  },
25
26
  },
26
- 'install-git-hooks': require('./install-git-hooks.cjs'),
27
- ...getPluginsObjectSync('scripts'),
28
27
  }
29
28
 
30
29
  exports.scripts = scripts
package/util/findUps.cjs CHANGED
@@ -1,10 +1,8 @@
1
1
  const findUp = require('find-up')
2
2
  const Path = require('path')
3
3
  const fs = require('fs-extra')
4
- const merge = require('lodash/merge')
5
4
  const once = require('./once.cjs')
6
5
  const { name } = require('../package.json')
7
- const configSchema = require('./configSchema.cjs')
8
6
 
9
7
  const findGitDir = once(function findGitDir(
10
8
  cwd = process.env.INIT_CWD || process.cwd()
@@ -26,19 +24,12 @@ if (!packageJsonFile) {
26
24
  }
27
25
  exports.packageJsonFile = packageJsonFile
28
26
  const packageJson = (exports.packageJson = fs.readJsonSync(packageJsonFile))
29
- const projectDir = (exports.projectDir = Path.dirname(packageJsonFile))
27
+ exports.projectDir = Path.dirname(packageJsonFile)
30
28
 
31
- const toolchainPackages = (exports.toolchainPackages = [
29
+ exports.toolchainPackages = [
32
30
  ...Object.keys(packageJson.dependencies || {}),
33
31
  ...Object.keys(packageJson.devDependencies || {}),
34
- ].filter((dep) => dep.startsWith(name)))
35
-
36
- const toolchainPackageJsons = (exports.toolchainPackageJsons = {})
37
- for (const pkg of toolchainPackages) {
38
- toolchainPackageJsons[pkg] = require(require.resolve(`${pkg}/package.json`, {
39
- paths: [projectDir],
40
- }))
41
- }
32
+ ].filter((dep) => dep.startsWith(name))
42
33
 
43
34
  let toolchainConfigFile
44
35
  try {
@@ -48,48 +39,6 @@ try {
48
39
  } catch (error) {
49
40
  // ignore
50
41
  }
51
-
52
- let toolchainConfig
53
- try {
54
- toolchainConfig = configSchema.parse(
55
- toolchainConfigFile ? require(toolchainConfigFile) : packageJson[name] || {}
56
- )
57
- } catch (error) {
58
- const toolchainConfigLocation = toolchainConfigFile
59
- ? Path.relative(cwd, toolchainConfigFile)
60
- : `packageJson[${JSON.stringify(name)}]`
61
-
62
- // eslint-disable-next-line no-console
63
- console.error(`invalid ${toolchainConfigLocation}`)
64
- // eslint-disable-next-line no-console
65
- console.error(error.message)
66
- process.exit(1)
67
- }
68
-
69
- exports.toolchainConfig = toolchainConfig
70
-
71
- const toolchainManaged = (exports.toolchainManaged = {})
72
- for (const toolchainPkgJson of Object.values(toolchainPackageJsons)) {
73
- const toolchainPkgDeps = toolchainPkgJson.dependencies || {}
74
- const toolchainPkgDevDeps = toolchainPkgJson.devDependencies || {}
75
- if (toolchainPkgJson.toolchainManaged) {
76
- for (const section in toolchainPkgJson.toolchainManaged) {
77
- if (!toolchainManaged[section]) toolchainManaged[section] = {}
78
- const sectionCfg = toolchainPkgJson.toolchainManaged[section]
79
- if (section.endsWith('ependencies')) {
80
- for (const dep in sectionCfg) {
81
- let version = sectionCfg[dep]
82
- if (version === '*')
83
- version = toolchainPkgDevDeps[dep] || toolchainPkgDeps[dep]
84
- if (version !== '*') toolchainManaged[section][dep] = version
85
- }
86
- continue
87
- }
88
- if (sectionCfg && typeof sectionCfg === 'object') {
89
- toolchainManaged[section] = merge(toolchainManaged[section], sectionCfg)
90
- continue
91
- }
92
- toolchainManaged[section] = sectionCfg
93
- }
94
- }
95
- }
42
+ exports.toolchainConfig = toolchainConfigFile
43
+ ? require(toolchainConfigFile)
44
+ : {}
@@ -0,0 +1,12 @@
1
+ const getPlugins = require('./getPlugins.cjs')
2
+
3
+ async function getPluginsObject(name, ...args) {
4
+ const plugins = getPlugins(name)
5
+ const result = {}
6
+ for (const plugin of plugins) {
7
+ Object.assign(result, await plugin(...args))
8
+ }
9
+ return result
10
+ }
11
+
12
+ module.exports = getPluginsObject
@@ -3,5 +3,5 @@ const once = require('./once.cjs')
3
3
 
4
4
  module.exports = once(function hasTSSourcesSync() {
5
5
  const files = fs.readdirSync('src')
6
- return files.some((f) => /\.[cm]?tsx?$/.test(f) && !/\.d\.[cm]?tsx?$/.test(f))
6
+ return files.find((f) => /\.tsx?$/.test(f) && !/\.d\.tsx?$/.test(f)) != null
7
7
  })
@@ -1,39 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const execa = require('../util/execa.cjs')
4
- const Path = require('path')
5
- const dedent = require('dedent-js')
6
- const { findGitDir } = require('../util/findUps.cjs')
7
- const fs = require('fs-extra')
8
-
9
- const githooksDir = Path.resolve(__dirname, '..', 'githooks')
10
-
11
- async function installGitHooks() {
12
- const gitDir = findGitDir()
13
- if (!gitDir) {
14
- // eslint-disable-next-line no-console
15
- console.warn(dedent`
16
- .git directory not found!
17
- git hooks could not be installed.
18
- after you run \`git init\`, try \`pnpm tc install-git-hooks\`.
19
- `)
20
- } else {
21
- // chmod in case pnpm doesn't preserve mode of hooks scripts
22
- await Promise.all(
23
- (
24
- await fs.readdir(githooksDir)
25
- ).map((hook) => fs.chmod(Path.join(githooksDir, hook), 0o755))
26
- )
27
- await execa('git', [
28
- 'config',
29
- 'core.hooksPath',
30
- Path.relative(Path.dirname(gitDir), githooksDir),
31
- ])
32
- // eslint-disable-next-line no-console
33
- console.log('successfully installed git hooks!')
34
- }
35
- }
36
-
37
- exports.description = 'install git hooks'
38
-
39
- exports.run = installGitHooks
@@ -1,7 +0,0 @@
1
- const z = require('zod')
2
-
3
- module.exports = z.object({
4
- cjsBabelEnv: z.record(z.unknown()).optional(),
5
- esmBabelEnv: z.record(z.unknown()).optional(),
6
- esWrapper: z.boolean().optional(),
7
- })
@@ -1,15 +0,0 @@
1
- const getPlugins = require('./getPlugins.cjs')
2
-
3
- async function getPluginsObjectAsync(name, ...args) {
4
- const plugins = getPlugins(name)
5
- const result = {}
6
- for (const plugin of plugins) {
7
- Object.assign(
8
- result,
9
- typeof plugin === 'function' ? await plugin(...args) : plugin
10
- )
11
- }
12
- return result
13
- }
14
-
15
- module.exports = getPluginsObjectAsync
@@ -1,15 +0,0 @@
1
- const getPlugins = require('./getPlugins.cjs')
2
-
3
- function getPluginsObjectSync(name, ...args) {
4
- const plugins = getPlugins(name)
5
- const result = {}
6
- for (const plugin of plugins) {
7
- Object.assign(
8
- result,
9
- typeof plugin === 'function' ? plugin(...args) : plugin
10
- )
11
- }
12
- return result
13
- }
14
-
15
- module.exports = getPluginsObjectSync
@@ -1,7 +0,0 @@
1
- const fs = require('./projectFs.cjs')
2
- const once = require('./once.cjs')
3
-
4
- module.exports = once(async function hasFlowFiles() {
5
- const files = await fs.readdir('src')
6
- return files.some((f) => /\.flow$/.test(f))
7
- })
@@ -1,7 +0,0 @@
1
- const fs = require('./projectFs.cjs')
2
- const once = require('./once.cjs')
3
-
4
- module.exports = once(async function hasTSFiles() {
5
- const files = await fs.readdir('src')
6
- return files.some((f) => /\.[cm]?tsx?$/.test(f))
7
- })
@@ -1,13 +0,0 @@
1
- const fs = require('./projectFs.cjs')
2
-
3
- async function hasYarnOrNpmLockfile() {
4
- return (
5
- await Promise.all(
6
- ['yarn.lock', 'npm-shrinkwrap.json', 'package-lock.json'].map((file) =>
7
- fs.pathExists(file)
8
- )
9
- )
10
- ).some((exists) => exists)
11
- }
12
-
13
- module.exports = hasYarnOrNpmLockfile
@@ -1,18 +0,0 @@
1
- module.exports = function replaceRanges(source, replacements) {
2
- replacements.sort((a, b) => a.start - b.start)
3
-
4
- const parts = []
5
- let end = 0
6
- for (const r of replacements) {
7
- if (r.start > end) {
8
- parts.push(source.substring(end, r.start))
9
- }
10
- parts.push(r.value)
11
- end = r.end
12
- }
13
- if (end < source.length) {
14
- parts.push(source.substring(end))
15
- }
16
-
17
- return parts.join('')
18
- }