@jcoreio/toolchain 1.0.0-beta.2 → 1.0.0-beta.3
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 +3 -2
- package/scripts/bootstrap/installGitHooks.cjs +10 -4
- package/util/configSchema.cjs +7 -0
- package/util/findUps.cjs +20 -3
- package/util/replaceRanges.cjs +18 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jcoreio/toolchain",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
4
4
|
"description": "base JS build toolchain",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
"prettier": "^2.5.1",
|
|
37
37
|
"resolve-bin": "^1.0.0",
|
|
38
38
|
"semantic-release": "^21.0.5",
|
|
39
|
-
"toposort": "^2.0.2"
|
|
39
|
+
"toposort": "^2.0.2",
|
|
40
|
+
"zod": "^3.21.4"
|
|
40
41
|
},
|
|
41
42
|
"peerDependencies": {
|
|
42
43
|
"eslint": "^8.0.0"
|
|
@@ -4,6 +4,9 @@ const execa = require('../../util/execa.cjs')
|
|
|
4
4
|
const Path = require('path')
|
|
5
5
|
const dedent = require('dedent-js')
|
|
6
6
|
const { findGitDir } = require('../../util/findUps.cjs')
|
|
7
|
+
const fs = require('fs-extra')
|
|
8
|
+
|
|
9
|
+
const githooksDir = Path.resolve(__dirname, '..', '..', 'githooks')
|
|
7
10
|
|
|
8
11
|
async function installGitHooks() {
|
|
9
12
|
const gitDir = findGitDir()
|
|
@@ -15,13 +18,16 @@ async function installGitHooks() {
|
|
|
15
18
|
after you run \`git init\`, try \`pnpm exec install-git-hooks\`.
|
|
16
19
|
`)
|
|
17
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
|
+
)
|
|
18
27
|
await execa('git', [
|
|
19
28
|
'config',
|
|
20
29
|
'core.hooksPath',
|
|
21
|
-
Path.relative(
|
|
22
|
-
Path.dirname(gitDir),
|
|
23
|
-
Path.resolve(__dirname, '..', '..', 'githooks')
|
|
24
|
-
),
|
|
30
|
+
Path.relative(Path.dirname(gitDir), githooksDir),
|
|
25
31
|
])
|
|
26
32
|
// eslint-disable-next-line no-console
|
|
27
33
|
console.log('successfully installed git hooks!')
|
package/util/findUps.cjs
CHANGED
|
@@ -3,6 +3,7 @@ const Path = require('path')
|
|
|
3
3
|
const fs = require('fs-extra')
|
|
4
4
|
const once = require('./once.cjs')
|
|
5
5
|
const { name } = require('../package.json')
|
|
6
|
+
const configSchema = require('./configSchema.cjs')
|
|
6
7
|
|
|
7
8
|
const findGitDir = once(function findGitDir(
|
|
8
9
|
cwd = process.env.INIT_CWD || process.cwd()
|
|
@@ -39,6 +40,22 @@ try {
|
|
|
39
40
|
} catch (error) {
|
|
40
41
|
// ignore
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
|
|
44
|
+
let toolchainConfig
|
|
45
|
+
try {
|
|
46
|
+
toolchainConfig = configSchema.parse(
|
|
47
|
+
toolchainConfigFile ? require(toolchainConfigFile) : packageJson[name] || {}
|
|
48
|
+
)
|
|
49
|
+
} catch (error) {
|
|
50
|
+
const toolchainConfigLocation = toolchainConfigFile
|
|
51
|
+
? Path.relative(cwd, toolchainConfigFile)
|
|
52
|
+
: `packageJson[${JSON.stringify(name)}]`
|
|
53
|
+
|
|
54
|
+
// eslint-disable-next-line no-console
|
|
55
|
+
console.error(`invalid ${toolchainConfigLocation}`)
|
|
56
|
+
// eslint-disable-next-line no-console
|
|
57
|
+
console.error(error.message)
|
|
58
|
+
process.exit(1)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
exports.toolchainConfig = toolchainConfig
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
}
|