@emeryld/manager 0.2.3 → 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)
@@ -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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emeryld/manager",
3
- "version": "0.2.3",
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",