@lvce-editor/shared-process 0.15.19 → 0.15.21

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/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { dirname, join } from 'node:path'
1
+ import { dirname, isAbsolute, join } from 'node:path'
2
2
  import { fileURLToPath } from 'node:url'
3
3
 
4
4
  const __dirname = dirname(fileURLToPath(import.meta.url))
@@ -10,7 +10,7 @@ export const exportStatic = async ({ extensionPath = process.cwd(), testPath = '
10
10
  throw new Error(`root argument is required`)
11
11
  }
12
12
  const fn = await import('./src/parts/ExportStatic/ExportStatic.js')
13
- if (extensionPath !== root) {
13
+ if (extensionPath !== root && !isAbsolute(extensionPath)) {
14
14
  extensionPath = join(root, extensionPath)
15
15
  }
16
16
  const pathPrefix = process.env.PATH_PREFIX || ''
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/shared-process",
3
- "version": "0.15.19",
3
+ "version": "0.15.21",
4
4
  "description": "Utility package for @lvce-editor/server",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -17,9 +17,9 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@babel/code-frame": "^7.21.4",
20
- "@lvce-editor/extension-host": "0.15.19",
21
- "@lvce-editor/extension-host-helper-process": "0.15.19",
22
- "@lvce-editor/pty-host": "0.15.19",
20
+ "@lvce-editor/extension-host": "0.15.21",
21
+ "@lvce-editor/extension-host-helper-process": "0.15.21",
22
+ "@lvce-editor/pty-host": "0.15.21",
23
23
  "debug": "^4.3.4",
24
24
  "execa": "^7.1.1",
25
25
  "exit-hook": "^3.2.0",
@@ -2,4 +2,4 @@ export const Error = 1
2
2
 
3
3
  export const ExpectedError = 128
4
4
 
5
- export const Sucess = 0
5
+ export const Success = 0
@@ -1,6 +1,8 @@
1
+ import { isAbsolute, join } from 'path'
1
2
  import * as FileSystem from '../FileSystem/FileSystem.js'
2
3
  import * as JsonFile from '../JsonFile/JsonFile.js'
3
4
  import * as Path from '../Path/Path.js'
5
+ import { existsSync } from 'fs'
4
6
 
5
7
  // TODO
6
8
  // - implement this for syntax highlighting projects
@@ -80,7 +82,7 @@ const isCommitHash = (dirent) => {
80
82
  * @param {string} root
81
83
  */
82
84
  const clean = async (root) => {
83
- await FileSystem.remove(Path.join(root, 'dist'))
85
+ await FileSystem.forceRemove(Path.join(root, 'dist'))
84
86
  await FileSystem.mkdir(Path.join(root, 'dist'))
85
87
  }
86
88
 
@@ -308,7 +310,7 @@ const addExtensionLanguages = async ({ root, extensionPath, extensionJson, commi
308
310
  return
309
311
  }
310
312
  const extensionId = extensionJson.id
311
- await FileSystem.remove(Path.join(root, 'dist', commitHash, 'extensions', extensionId))
313
+ await FileSystem.forceRemove(Path.join(root, 'dist', commitHash, 'extensions', extensionId))
312
314
  await FileSystem.mkdir(Path.join(root, 'dist', commitHash, 'extensions', extensionId))
313
315
  await FileSystem.copyFile(Path.join(root, 'README.md'), Path.join(root, 'dist', commitHash, 'extensions', extensionId, 'README.md'))
314
316
  for (const file of ['src', 'data', 'extension.json']) {
@@ -330,7 +332,7 @@ const addExtensionLanguages = async ({ root, extensionPath, extensionJson, commi
330
332
  const mergedLanguages = mergeLanguages(builtinLanguages, extensionLanguages)
331
333
  await JsonFile.writeJson(Path.join(root, 'dist', commitHash, 'config', 'languages.json'), mergedLanguages)
332
334
  if (await FileSystem.exists(Path.join(extensionPath, 'test', 'cases'))) {
333
- await FileSystem.remove(Path.join(root, 'dist', commitHash, 'playground'))
335
+ await FileSystem.forceRemove(Path.join(root, 'dist', commitHash, 'playground'))
334
336
  await FileSystem.copy(Path.join(extensionPath, 'test', 'cases'), Path.join(root, 'dist', commitHash, 'playground'))
335
337
  const testFiles = await FileSystem.readDir(Path.join(extensionPath, 'test', 'cases'))
336
338
  const fileMap = testFiles.map(toPlaygroundFile)
@@ -426,12 +428,12 @@ const getTestFiles = (testFilesRaw) => {
426
428
  }
427
429
 
428
430
  const addTestFiles = async ({ testPath, commitHash, root, pathPrefix }) => {
429
- await FileSystem.copy(`${root}/${testPath}/src`, `${root}/dist/${commitHash}/packages/extension-host-worker-tests/src`)
430
- const testFilesRaw = await FileSystem.readDir(`${root}/${testPath}/src`)
431
+ const testRoot = isAbsolute(testPath) ? testPath : join(root, testPath)
432
+ await FileSystem.copy(`${testRoot}/src`, `${root}/dist/${commitHash}/packages/extension-host-worker-tests/src`)
433
+ const testFilesRaw = await FileSystem.readDir(`${testRoot}/src`)
431
434
  const testFiles = getTestFiles(testFilesRaw)
432
435
  await FileSystem.mkdir(`${root}/dist/${commitHash}/tests`)
433
436
  await FileSystem.mkdir(`${root}/dist/tests`)
434
- console.log({ testFiles })
435
437
  for (const testFile of testFiles) {
436
438
  await FileSystem.copyFile(`${root}/dist/index.html`, `${root}/dist/tests/${testFile}.html`)
437
439
  }
@@ -444,6 +446,12 @@ const addTestFiles = async ({ testPath, commitHash, root, pathPrefix }) => {
444
446
  * @param {{root:string, pathPrefix:string , extensionPath:string, testPath:string }} param0
445
447
  */
446
448
  export const exportStatic = async ({ root, pathPrefix, extensionPath, testPath }) => {
449
+ if (!existsSync(root)) {
450
+ throw new Error(`root path does not exist: ${root}`)
451
+ }
452
+ if (!existsSync(extensionPath)) {
453
+ throw new Error(`extension path does not exist: ${extensionPath}`)
454
+ }
447
455
  if (pathPrefix === 'auto') {
448
456
  const extensionJson = await readExtensionManifest(Path.join(extensionPath, 'extension.json'))
449
457
  const { id } = extensionJson
@@ -123,6 +123,18 @@ export const remove = async (path) => {
123
123
  }
124
124
  }
125
125
 
126
+ export const forceRemove = async (path) => {
127
+ if (!isOkayToRemove(path)) {
128
+ console.warn('not removing path')
129
+ return
130
+ }
131
+ try {
132
+ await fs.rm(path, { force: true, recursive: true })
133
+ } catch (error) {
134
+ throw new VError(error, `Failed to remove "${path}"`)
135
+ }
136
+ }
137
+
126
138
  export const exists = async (path) => {
127
139
  try {
128
140
  await fs.access(path)
@@ -1,2 +1,3 @@
1
1
  export const SIGUSR1 = 'SIGUSR1'
2
2
  export const SIGTERM = 'SIGTERM'
3
+ export const SIGINT = 'SIGINT'
@@ -1,8 +1,8 @@
1
- import { default as _trash } from 'trash'
2
1
  import { VError } from '../VError/VError.js'
3
2
 
4
3
  export const trash = async (path) => {
5
4
  try {
5
+ const { default: _trash } = await import('trash')
6
6
  await _trash(path)
7
7
  } catch (error) {
8
8
  throw new VError(error, 'Failed to move item to trash')
@@ -1,5 +1,6 @@
1
1
  import * as Command from './parts/Command/Command.js'
2
2
  import * as ErrorHandling from './parts/ErrorHandling/ErrorHandling.js'
3
+ import * as ExitCode from './parts/ExitCode/ExitCode.js'
3
4
  import * as Module from './parts/Module/Module.js'
4
5
  import * as ParentIpc from './parts/ParentIpc/ParentIpc.js'
5
6
  import * as Process from './parts/Process/Process.js'
@@ -10,6 +11,7 @@ import * as Signal from './parts/Signal/Signal.js'
10
11
 
11
12
  const handleDisconnect = () => {
12
13
  console.info('[shared process] disconnected')
14
+ Process.exit(ExitCode.Success)
13
15
  }
14
16
 
15
17
  // const handleBeforeExit = () => {
@@ -18,6 +20,7 @@ const handleDisconnect = () => {
18
20
 
19
21
  const handleSigTerm = () => {
20
22
  console.info('[shared-process] sigterm')
23
+ Process.exit(ExitCode.Success)
21
24
  }
22
25
 
23
26
  const knownCliArgs = ['install', 'list', 'link', 'unlink']
@@ -31,22 +34,11 @@ const main = async () => {
31
34
  await module.handleCliArgs(argv)
32
35
  return
33
36
  }
34
-
35
- console.log('[shared process] started')
36
37
  // process.on('beforeExit', handleBeforeExit)
37
38
  process.on('disconnect', handleDisconnect)
38
39
  process.on(Signal.SIGTERM, handleSigTerm)
39
-
40
40
  process.on('uncaughtExceptionMonitor', ErrorHandling.handleUncaughtExceptionMonitor)
41
41
  await ParentIpc.listen()
42
-
43
- // ExtensionHost.start() // TODO start on demand, e.g. not when extensions should be disabled
44
42
  }
45
43
 
46
44
  main()
47
-
48
- // TODO when browser reloads or opens in new tab how does the window know which folder to open?
49
-
50
- // setTimeout(() => {
51
- // throw new Error('oops')
52
- // }, 210)