@applicaster/zapplicaster-cli 17.0.0-alpha.1037440043 → 17.0.0-alpha.1201533844
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/package.json +5 -5
- package/src/commands/publishPlugin/__tests__/npmPublish.test.js +39 -23
- package/src/commands/publishPlugin/npmPublish.js +6 -9
- package/src/commands/publishPlugin/updateCorePluginsIfNeeded.js +7 -0
- package/src/file/__tests__/file.test.js +7 -1
- package/src/file/index.js +14 -3
- package/test_helpers/fsMock.js +11 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapplicaster-cli",
|
|
3
|
-
"version": "17.0.0-alpha.
|
|
3
|
+
"version": "17.0.0-alpha.1201533844",
|
|
4
4
|
"description": "CLI Tool for the zapp app and Quick Brick project",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@applicaster/zapp-react-dom-cli-template": "17.0.0-alpha.
|
|
32
|
-
"@applicaster/zapp-react-native-android-tv-cli-template": "17.0.0-alpha.
|
|
33
|
-
"@applicaster/zapp-react-native-cli-template": "17.0.0-alpha.
|
|
34
|
-
"@applicaster/zapp-react-native-tvos-cli-template": "17.0.0-alpha.
|
|
31
|
+
"@applicaster/zapp-react-dom-cli-template": "17.0.0-alpha.1201533844",
|
|
32
|
+
"@applicaster/zapp-react-native-android-tv-cli-template": "17.0.0-alpha.1201533844",
|
|
33
|
+
"@applicaster/zapp-react-native-cli-template": "17.0.0-alpha.1201533844",
|
|
34
|
+
"@applicaster/zapp-react-native-tvos-cli-template": "17.0.0-alpha.1201533844",
|
|
35
35
|
"@applicaster/zappifest-nano": "^1.0.0",
|
|
36
36
|
"axios": "^0.28.0",
|
|
37
37
|
"camelize": "^1.0.0",
|
|
@@ -42,11 +42,21 @@ const { npmPublish } = require("../npmPublish");
|
|
|
42
42
|
const { runInShellAsync } = require("../../../shell");
|
|
43
43
|
const logger = require("../../../logger");
|
|
44
44
|
const { retryPublishCommand } = require("../../utils/retryPublishCommand");
|
|
45
|
+
const { readJsonFile, writeJsonToFile } = require("../../../file");
|
|
46
|
+
|
|
47
|
+
jest.mock("../../../file", () => ({
|
|
48
|
+
readJsonFile: jest.fn(() =>
|
|
49
|
+
Promise.resolve({ name: "my-plugin", version: "1.0.0" })
|
|
50
|
+
),
|
|
51
|
+
writeJsonToFile: jest.fn(() => Promise.resolve()),
|
|
52
|
+
}));
|
|
45
53
|
|
|
46
54
|
function clearMocks() {
|
|
47
55
|
logger.log.mockClear();
|
|
48
56
|
retryPublishCommand.mockClear();
|
|
49
57
|
runInShellAsync.mockClear();
|
|
58
|
+
if (writeJsonToFile.mockClear) writeJsonToFile.mockClear();
|
|
59
|
+
if (readJsonFile.mockClear) readJsonFile.mockClear();
|
|
50
60
|
jest.resetModules();
|
|
51
61
|
}
|
|
52
62
|
|
|
@@ -58,12 +68,10 @@ describe("npm publish step", () => {
|
|
|
58
68
|
const configuration = getConfig();
|
|
59
69
|
expect(await npmPublish(configuration)).toEqual(true);
|
|
60
70
|
expect(retryPublishCommand).toHaveBeenCalledTimes(1);
|
|
61
|
-
expect(runInShellAsync).toHaveBeenCalledTimes(1);
|
|
62
71
|
|
|
63
|
-
expect(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
expect.objectContaining({ cwd: configuration.pluginPath })
|
|
72
|
+
expect(writeJsonToFile).toHaveBeenCalledWith(
|
|
73
|
+
"plugins/my-plugin/package.json",
|
|
74
|
+
expect.objectContaining({ version: configuration.version })
|
|
67
75
|
);
|
|
68
76
|
|
|
69
77
|
expect(retryPublishCommand).toHaveBeenNthCalledWith(
|
|
@@ -75,8 +83,12 @@ describe("npm publish step", () => {
|
|
|
75
83
|
});
|
|
76
84
|
|
|
77
85
|
it("throws if the npm command fails", async () => {
|
|
78
|
-
|
|
79
|
-
|
|
86
|
+
retryPublishCommand.mockImplementationOnce(() =>
|
|
87
|
+
Promise.reject(mock_publish_error)
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const configuration = getConfig();
|
|
91
|
+
await expect(npmPublish(configuration)).rejects.toMatchSnapshot();
|
|
80
92
|
});
|
|
81
93
|
|
|
82
94
|
it.skip("re tries 3 times if the npm command fails with ESOCKETTIMEDOUT", async () => {
|
|
@@ -134,15 +146,14 @@ describe("npm publish step", () => {
|
|
|
134
146
|
const configuration = getConfig({ dryRun: true });
|
|
135
147
|
|
|
136
148
|
expect(await npmPublish(configuration)).toEqual(true);
|
|
137
|
-
expect(runInShellAsync).toHaveBeenCalledTimes(1);
|
|
138
|
-
expect(retryPublishCommand).toHaveBeenCalledTimes(1);
|
|
139
149
|
|
|
140
|
-
expect(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
expect.objectContaining({ cwd: configuration.pluginPath })
|
|
150
|
+
expect(writeJsonToFile).toHaveBeenCalledWith(
|
|
151
|
+
"plugins/my-plugin/package.json",
|
|
152
|
+
expect.objectContaining({ version: configuration.version })
|
|
144
153
|
);
|
|
145
154
|
|
|
155
|
+
expect(retryPublishCommand).toHaveBeenCalledTimes(1);
|
|
156
|
+
|
|
146
157
|
expect(retryPublishCommand).toHaveBeenNthCalledWith(
|
|
147
158
|
1,
|
|
148
159
|
"npm publish --dry-run",
|
|
@@ -167,15 +178,13 @@ describe("npm publish step", () => {
|
|
|
167
178
|
|
|
168
179
|
expect(await npmPublish(configuration)).toEqual(true);
|
|
169
180
|
|
|
170
|
-
expect(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
expect(runInShellAsync).toHaveBeenNthCalledWith(
|
|
174
|
-
1,
|
|
175
|
-
`npm version ${configuration.version}`,
|
|
176
|
-
expect.objectContaining({ cwd: configuration.pluginPath })
|
|
181
|
+
expect(writeJsonToFile).toHaveBeenCalledWith(
|
|
182
|
+
"plugins/my-plugin/package.json",
|
|
183
|
+
expect.objectContaining({ version: configuration.version })
|
|
177
184
|
);
|
|
178
185
|
|
|
186
|
+
expect(retryPublishCommand).toHaveBeenCalledTimes(1);
|
|
187
|
+
|
|
179
188
|
expect(retryPublishCommand).toHaveBeenNthCalledWith(
|
|
180
189
|
1,
|
|
181
190
|
"npm publish --tag next",
|
|
@@ -190,9 +199,16 @@ describe("npm publish step", () => {
|
|
|
190
199
|
expect(await npmPublish(configuration)).toEqual(true);
|
|
191
200
|
expect(retryPublishCommand).toHaveBeenCalledTimes(1);
|
|
192
201
|
|
|
193
|
-
expect(
|
|
194
|
-
|
|
195
|
-
expect.objectContaining({
|
|
202
|
+
expect(writeJsonToFile).toHaveBeenCalledWith(
|
|
203
|
+
"plugins/my-plugin/package.json",
|
|
204
|
+
expect.objectContaining({ version: configuration.version })
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
expect(retryPublishCommand).toHaveBeenNthCalledWith(
|
|
208
|
+
1,
|
|
209
|
+
"npm publish --tag next",
|
|
210
|
+
expect.objectContaining({ cwd: configuration.pluginPath }),
|
|
211
|
+
configuration.version
|
|
196
212
|
);
|
|
197
213
|
});
|
|
198
214
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
const
|
|
1
|
+
const path = require("path");
|
|
2
2
|
const logger = require("../../logger");
|
|
3
3
|
const { retryPublishCommand } = require("../utils/retryPublishCommand");
|
|
4
|
+
const { readJsonFile, writeJsonToFile } = require("../../file");
|
|
4
5
|
|
|
5
6
|
async function npmPublish(configuration) {
|
|
6
7
|
const { dryRun, yarn, next, version, pluginPath, manifestOnly } =
|
|
@@ -29,14 +30,10 @@ async function npmPublish(configuration) {
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
if (version) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
);
|
|
37
|
-
} else {
|
|
38
|
-
await runInShellAsync(`npm version ${version}`, cmdOptions);
|
|
39
|
-
}
|
|
33
|
+
const packageJsonPath = path.join(pluginPath, "package.json");
|
|
34
|
+
const packageJson = await readJsonFile(packageJsonPath);
|
|
35
|
+
packageJson.version = version;
|
|
36
|
+
await writeJsonToFile(packageJsonPath, packageJson);
|
|
40
37
|
}
|
|
41
38
|
|
|
42
39
|
await retryPublishCommand(publishCommand, cmdOptions, version);
|
|
@@ -44,6 +44,13 @@ async function doUpdateCorePlugins(configuration) {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
async function updateCorePluginsIfNeeded(configuration) {
|
|
47
|
+
// During monorepo deploy (--skip-git), scripts/deploy updates quick-brick-core-plugins
|
|
48
|
+
// once in memory across all published plugins and writes it prior to its own publish.
|
|
49
|
+
// Skipping here prevents concurrent workers from racing to overwrite the file on disk.
|
|
50
|
+
if (configuration.skipGit) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
47
54
|
// Ensure that concurrent publishing tasks do not race when updating core plugins
|
|
48
55
|
const result = writeLock.then(() => doUpdateCorePlugins(configuration));
|
|
49
56
|
writeLock = result.catch(() => {});
|
|
@@ -22,10 +22,16 @@ describe("writeJsonTofile", () => {
|
|
|
22
22
|
await writeJsonToFile(filePath, json);
|
|
23
23
|
|
|
24
24
|
expect(fs.writeFile).toHaveBeenCalledWith(
|
|
25
|
-
|
|
25
|
+
expect.stringMatching(/^someFile\.json\.tmp\./),
|
|
26
26
|
JSON.stringify(json, null, 2),
|
|
27
27
|
expect.any(Function)
|
|
28
28
|
);
|
|
29
|
+
|
|
30
|
+
expect(fs.rename).toHaveBeenCalledWith(
|
|
31
|
+
expect.stringMatching(/^someFile\.json\.tmp\./),
|
|
32
|
+
filePath,
|
|
33
|
+
expect.any(Function)
|
|
34
|
+
);
|
|
29
35
|
});
|
|
30
36
|
});
|
|
31
37
|
|
package/src/file/index.js
CHANGED
|
@@ -5,23 +5,34 @@ const R = require("ramda");
|
|
|
5
5
|
* @module @applicaster/zapplicaster-cli/util/file
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
const {
|
|
8
|
+
const {
|
|
9
|
+
writeFile,
|
|
10
|
+
readFile,
|
|
11
|
+
readdir,
|
|
12
|
+
copyFile,
|
|
13
|
+
copyFileSync,
|
|
14
|
+
rename,
|
|
15
|
+
} = require("fs");
|
|
16
|
+
|
|
9
17
|
const { promisify } = require("util");
|
|
10
18
|
const { join } = require("path");
|
|
11
19
|
|
|
12
20
|
const writeFileAsync = promisify(writeFile);
|
|
21
|
+
const renameAsync = promisify(rename);
|
|
13
22
|
const readFileAsync = promisify(readFile);
|
|
14
23
|
const readdirAsync = promisify(readdir);
|
|
15
24
|
const copyFileAsync = promisify(copyFile);
|
|
16
25
|
|
|
17
26
|
/**
|
|
18
|
-
* Writes a pretty-printed json file from a javascript object
|
|
27
|
+
* Writes a pretty-printed json file from a javascript object atomically
|
|
19
28
|
* @param {String} path : path of the file to write
|
|
20
29
|
* @param {Object} object : object to write to the file
|
|
21
30
|
* @returns {Promise}
|
|
22
31
|
*/
|
|
23
32
|
async function writeJsonToFile(path, object) {
|
|
24
|
-
|
|
33
|
+
const tmpPath = `${path}.tmp.${Date.now()}.${Math.random().toString(36).slice(2, 6)}`;
|
|
34
|
+
await writeFileAsync(tmpPath, JSON.stringify(object, null, 2));
|
|
35
|
+
await renameAsync(tmpPath, path);
|
|
25
36
|
}
|
|
26
37
|
|
|
27
38
|
/**
|
package/test_helpers/fsMock.js
CHANGED
|
@@ -48,6 +48,16 @@ function copyFileSync() {
|
|
|
48
48
|
return { status: "ok" };
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
function rename(oldPath, newPath, callback) {
|
|
52
|
+
const file = fs.__writenFiles.find((f) => f.fileName === oldPath);
|
|
53
|
+
|
|
54
|
+
if (file) {
|
|
55
|
+
file.fileName = newPath;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
callback(null);
|
|
59
|
+
}
|
|
60
|
+
|
|
51
61
|
function existsSync(path) {
|
|
52
62
|
return R.includes(path, R.map(R.prop("fileName"), fs.__writenFiles));
|
|
53
63
|
}
|
|
@@ -87,6 +97,7 @@ fs.readFile = jest.fn(readFile);
|
|
|
87
97
|
fs.readFileSync = jest.fn(readFileSync);
|
|
88
98
|
fs.copyFile = jest.fn(copyFile);
|
|
89
99
|
fs.copyFileSync = jest.fn(copyFileSync);
|
|
100
|
+
fs.rename = jest.fn(rename);
|
|
90
101
|
fs.existsSync = jest.fn(existsSync);
|
|
91
102
|
fs.statSync = jest.fn(statSync);
|
|
92
103
|
|