@emeryld/manager 0.2.2 → 0.2.4

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.
@@ -1,28 +1,46 @@
1
1
  #!/usr/bin/env node
2
2
  import { spawnSync } from 'node:child_process'
3
+ import { existsSync } from 'node:fs'
3
4
  import path from 'node:path'
4
- import { fileURLToPath, pathToFileURL } from 'node:url'
5
+ import { fileURLToPath } from 'node:url'
5
6
  import { createRequire } from 'node:module'
6
7
 
7
8
  const __filename = fileURLToPath(import.meta.url)
8
9
  const __dirname = path.dirname(__filename)
9
10
  const packageRoot = path.resolve(__dirname, '..')
10
11
  const tsconfigPath = path.join(packageRoot, 'tsconfig.base.json')
11
- const entryPoint = path.join(packageRoot, 'src', 'publish.ts')
12
+ const compiledEntry = path.join(packageRoot, 'dist', 'publish.js')
13
+ const sourceEntry = path.join(packageRoot, 'src', 'publish.ts')
14
+ const args = process.argv.slice(2)
12
15
 
13
- const require = createRequire(import.meta.url)
14
- const tsNodeLoader = require.resolve('ts-node/esm.mjs')
15
- const registerCode = [
16
- 'import { register } from "node:module";',
17
- 'import { pathToFileURL } from "node:url";',
18
- `register(${JSON.stringify(tsNodeLoader)}, pathToFileURL(${JSON.stringify(packageRoot + path.sep)}));`,
19
- ].join(' ')
20
- const registerImport = `data:text/javascript,${encodeURIComponent(registerCode)}`
16
+ const hasCompiledEntry = existsSync(compiledEntry)
17
+ const hasSourceEntry = existsSync(sourceEntry)
21
18
 
22
- const nodeArgs = ['--import', registerImport, entryPoint, ...process.argv.slice(2)]
23
- const execOptions = {
24
- env: { ...process.env, TS_NODE_PROJECT: tsconfigPath },
25
- stdio: 'inherit',
19
+ let nodeArgs
20
+ let execOptions
21
+
22
+ if (hasCompiledEntry) {
23
+ nodeArgs = [compiledEntry, ...args]
24
+ execOptions = { env: process.env, stdio: 'inherit' }
25
+ } else if (hasSourceEntry) {
26
+ const require = createRequire(import.meta.url)
27
+ const tsNodeLoader = require.resolve('ts-node/esm.mjs')
28
+ const registerCode = [
29
+ 'import { register } from "node:module";',
30
+ 'import { pathToFileURL } from "node:url";',
31
+ `register(${JSON.stringify(tsNodeLoader)}, pathToFileURL(${JSON.stringify(packageRoot + path.sep)}));`,
32
+ ].join(' ')
33
+ const registerImport = `data:text/javascript,${encodeURIComponent(registerCode)}`
34
+ nodeArgs = ['--import', registerImport, sourceEntry, ...args]
35
+ execOptions = {
36
+ env: { ...process.env, TS_NODE_PROJECT: tsconfigPath },
37
+ stdio: 'inherit',
38
+ }
39
+ } else {
40
+ console.error(
41
+ `manager-cli could not find a publish entry point (checked ${compiledEntry} and ${sourceEntry}).`,
42
+ )
43
+ process.exit(1)
26
44
  }
27
45
 
28
46
  const child = spawnSync(process.execPath, nodeArgs, execOptions)
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from 'node:child_process'
3
+ import { existsSync } from 'node:fs'
4
+ import path from 'node:path'
5
+ import { fileURLToPath } from 'node:url'
6
+ import { createRequire } from 'node:module'
7
+
8
+ const __filename = fileURLToPath(import.meta.url)
9
+ const __dirname = path.dirname(__filename)
10
+ const packageRoot = path.resolve(__dirname, '..')
11
+ const tsconfigPath = path.join(packageRoot, 'tsconfig.base.json')
12
+ const compiledEntry = path.join(packageRoot, 'dist', 'publish.js')
13
+ const sourceEntry = path.join(packageRoot, 'src', 'publish.ts')
14
+ const args = process.argv.slice(2)
15
+
16
+ const hasCompiledEntry = existsSync(compiledEntry)
17
+ const hasSourceEntry = existsSync(sourceEntry)
18
+
19
+ let nodeArgs
20
+ let execOptions
21
+
22
+ if (hasCompiledEntry) {
23
+ nodeArgs = [compiledEntry, ...args]
24
+ execOptions = { env: process.env, stdio: 'inherit' }
25
+ } else if (hasSourceEntry) {
26
+ const require = createRequire(import.meta.url)
27
+ const tsNodeLoader = require.resolve('ts-node/esm.mjs')
28
+ const registerCode = [
29
+ 'import { register } from "node:module";',
30
+ 'import { pathToFileURL } from "node:url";',
31
+ `register(${JSON.stringify(tsNodeLoader)}, pathToFileURL(${JSON.stringify(packageRoot + path.sep)}));`,
32
+ ].join(' ')
33
+ const registerImport = `data:text/javascript,${encodeURIComponent(registerCode)}`
34
+ nodeArgs = ['--import', registerImport, sourceEntry, ...args]
35
+ execOptions = {
36
+ env: { ...process.env, TS_NODE_PROJECT: tsconfigPath },
37
+ stdio: 'inherit',
38
+ }
39
+ } else {
40
+ console.error(
41
+ `manager-cli could not find a publish entry point (checked ${compiledEntry} and ${sourceEntry}).`,
42
+ )
43
+ process.exit(1)
44
+ }
45
+
46
+ const child = spawnSync(process.execPath, nodeArgs, execOptions)
47
+ if (child.error) throw child.error
48
+ if (child.signal) {
49
+ process.kill(process.pid, child.signal)
50
+ } else {
51
+ process.exit(child.status ?? 0)
52
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emeryld/manager",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Interactive manager for pnpm monorepos (update/test/build/publish).",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -39,7 +39,7 @@
39
39
  "swc": false
40
40
  },
41
41
  "scripts": {
42
- "build": "tsc -p tsconfig.base.json",
42
+ "build": "tsc -p tsconfig.base.json && node scripts/copy-manager-cli.mjs",
43
43
  "typecheck": "tsc -p tsconfig.base.json --noEmit",
44
44
  "test": "cross-env TS_NODE_PROJECT=tsconfig.test.json node --loader ts-node/esm test/helper-cli.test.ts"
45
45
  }