@salesforce/pwa-kit-dev 3.8.0-preview.0-basepath → 3.8.0-preview.2-basepath
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/configs/babel/babel-config.js +33 -0
- package/configs/eslint/README.md +21 -0
- package/configs/eslint/eslint-config.js +11 -0
- package/configs/eslint/index.js +11 -0
- package/configs/eslint/no-react.js +18 -0
- package/configs/eslint/partials/base.js +38 -0
- package/configs/eslint/partials/jest.js +24 -0
- package/configs/eslint/partials/react.js +29 -0
- package/configs/eslint/partials/typescript-permit-any.js +31 -0
- package/configs/eslint/partials/typescript.js +17 -0
- package/configs/eslint/recommended.js +20 -0
- package/configs/eslint/safe-types.js +20 -0
- package/configs/jest/jest-babel-transform.js +19 -0
- package/configs/jest/jest.config.js +40 -0
- package/configs/jest/mocks/fileMock.js +9 -0
- package/configs/jest/mocks/styleMock.js +9 -0
- package/configs/jest/mocks/svgMock.js +11 -0
- package/configs/webpack/config-names.js +19 -0
- package/configs/webpack/config.js +406 -0
- package/configs/webpack/overrides-plugin.js +168 -0
- package/configs/webpack/overrides-plugin.test.js +388 -0
- package/configs/webpack/plugins.js +86 -0
- package/configs/webpack/test/overrides/exists.js +7 -0
- package/configs/webpack/test/overrides/newExtension.js +7 -0
- package/configs/webpack/test/overrides/path/data.js +7 -0
- package/configs/webpack/test/overrides/path/index.js +7 -0
- package/configs/webpack/test/overrides/path/index.mock.js +7 -0
- package/configs/webpack/test/overrides/path/nested/icon.svg +0 -0
- package/configs/webpack/test/package.json +13 -0
- package/configs/webpack/utils.js +23 -0
- package/package.json +5 -4
- package/ssr/server/build-dev-server.js +468 -0
- package/ssr/server/build-dev-server.test.js +661 -0
- package/ssr/server/loading-screen/css/main.css +272 -0
- package/ssr/server/loading-screen/css/normalize.css +349 -0
- package/ssr/server/loading-screen/img/cloud-1.svg +1 -0
- package/ssr/server/loading-screen/img/cloud-2.svg +1 -0
- package/ssr/server/loading-screen/img/cloud-3.svg +1 -0
- package/ssr/server/loading-screen/img/cloud.svg +1 -0
- package/ssr/server/loading-screen/img/codey-arm.svg +1 -0
- package/ssr/server/loading-screen/img/codey-bear.svg +1 -0
- package/ssr/server/loading-screen/img/codey-bg.svg +1 -0
- package/ssr/server/loading-screen/img/codey-cloud.svg +1 -0
- package/ssr/server/loading-screen/img/codey-search.svg +1 -0
- package/ssr/server/loading-screen/img/codey.svg +1 -0
- package/ssr/server/loading-screen/img/codeyCarry.svg +1 -0
- package/ssr/server/loading-screen/img/devDocumentation.svg +1 -0
- package/ssr/server/loading-screen/img/devGithub.svg +1 -0
- package/ssr/server/loading-screen/img/devTrailhead.svg +1 -0
- package/ssr/server/loading-screen/img/logo.svg +1 -0
- package/ssr/server/loading-screen/img/slds_spinner_brand_9EA9F1.gif +0 -0
- package/ssr/server/loading-screen/index.html +129 -0
- package/ssr/server/test_fixtures/app/main.js +6 -0
- package/ssr/server/test_fixtures/app/static/favicon.ico +0 -0
- package/ssr/server/test_fixtures/localhost.pem +45 -0
- package/utils/mocks/dependency-tree-mock-data.js +127 -0
- package/utils/script-utils.js +497 -0
- package/utils/script-utils.test.js +496 -0
- package/utils/test-fixtures/minimal-built-app/ssr.js +9 -0
- package/utils/test-fixtures/minimal-built-app/static/favicon.ico +0 -0
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.walkDir = exports.readCredentials = exports.parseLog = exports.glob = exports.getPwaKitDependencies = exports.getProjectPkg = exports.getProjectDependencyTree = exports.getPkgJSON = exports.getLowestPackageVersion = exports.getCredentialsFile = exports.defaultMessage = exports.createBundle = exports.DEFAULT_DOCS_URL = exports.DEFAULT_CLOUD_ORIGIN = exports.CloudAPIClient = void 0;
|
|
7
|
+
var _os = _interopRequireDefault(require("os"));
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
var _archiver = _interopRequireDefault(require("archiver"));
|
|
10
|
+
var _nodeFetch = _interopRequireDefault(require("node-fetch"));
|
|
11
|
+
var _url = require("url");
|
|
12
|
+
var _fsExtra = require("fs-extra");
|
|
13
|
+
var _minimatch = require("minimatch");
|
|
14
|
+
var _gitRevSync = _interopRequireDefault(require("git-rev-sync"));
|
|
15
|
+
var _validator = _interopRequireDefault(require("validator"));
|
|
16
|
+
var _child_process = require("child_process");
|
|
17
|
+
var _semver = _interopRequireDefault(require("semver"));
|
|
18
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
20
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
21
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
22
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
23
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
24
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
25
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } /*
|
|
26
|
+
* Copyright (c) 2022, Salesforce, Inc.
|
|
27
|
+
* All rights reserved.
|
|
28
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
29
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
30
|
+
*/
|
|
31
|
+
const DEFAULT_CLOUD_ORIGIN = exports.DEFAULT_CLOUD_ORIGIN = 'https://cloud.mobify.com';
|
|
32
|
+
const DEFAULT_DOCS_URL = exports.DEFAULT_DOCS_URL = 'https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/pushing-and-deploying-bundles.html';
|
|
33
|
+
/**
|
|
34
|
+
* Get the package info for pwa-kit-dev.
|
|
35
|
+
*/
|
|
36
|
+
const getPkgJSON = exports.getPkgJSON = /*#__PURE__*/function () {
|
|
37
|
+
var _ref = _asyncToGenerator(function* () {
|
|
38
|
+
const candidates = [_path.default.join(__dirname, '..', 'package.json'), _path.default.join(__dirname, '..', '..', 'package.json')];
|
|
39
|
+
for (const candidate of candidates) {
|
|
40
|
+
try {
|
|
41
|
+
const data = yield (0, _fsExtra.readJson)(candidate);
|
|
42
|
+
return data;
|
|
43
|
+
} catch {
|
|
44
|
+
// Keep looking
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
name: '@salesforce/pwa-kit-dev',
|
|
49
|
+
version: 'unknown'
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
return function getPkgJSON() {
|
|
53
|
+
return _ref.apply(this, arguments);
|
|
54
|
+
};
|
|
55
|
+
}();
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Get the package info for the current project.
|
|
59
|
+
*/
|
|
60
|
+
const getProjectPkg = exports.getProjectPkg = /*#__PURE__*/function () {
|
|
61
|
+
var _ref2 = _asyncToGenerator(function* () {
|
|
62
|
+
const p = _path.default.join(process.cwd(), 'package.json');
|
|
63
|
+
try {
|
|
64
|
+
const data = yield (0, _fsExtra.readJson)(p);
|
|
65
|
+
return data;
|
|
66
|
+
} catch {
|
|
67
|
+
throw new Error(`Could not read project package at "${p}"`);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return function getProjectPkg() {
|
|
71
|
+
return _ref2.apply(this, arguments);
|
|
72
|
+
};
|
|
73
|
+
}();
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Get the set of file paths within a specific directory
|
|
77
|
+
* @param dir Directory to walk
|
|
78
|
+
* @returns Set of file paths within the directory
|
|
79
|
+
*/
|
|
80
|
+
const walkDir = exports.walkDir = /*#__PURE__*/function () {
|
|
81
|
+
var _ref3 = _asyncToGenerator(function* (dir, baseDir, fileSet) {
|
|
82
|
+
fileSet = fileSet || new Set();
|
|
83
|
+
const entries = yield (0, _fsExtra.readdir)(dir, {
|
|
84
|
+
withFileTypes: true
|
|
85
|
+
});
|
|
86
|
+
yield Promise.all(entries.map( /*#__PURE__*/function () {
|
|
87
|
+
var _ref4 = _asyncToGenerator(function* (entry) {
|
|
88
|
+
const entryPath = _path.default.join(dir, entry.name);
|
|
89
|
+
if (entry.isDirectory()) {
|
|
90
|
+
yield walkDir(entryPath, baseDir, fileSet);
|
|
91
|
+
} else {
|
|
92
|
+
var _fileSet;
|
|
93
|
+
(_fileSet = fileSet) === null || _fileSet === void 0 ? void 0 : _fileSet.add(entryPath.replace(baseDir + _path.default.sep, ''));
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return function (_x4) {
|
|
97
|
+
return _ref4.apply(this, arguments);
|
|
98
|
+
};
|
|
99
|
+
}()));
|
|
100
|
+
return fileSet;
|
|
101
|
+
});
|
|
102
|
+
return function walkDir(_x, _x2, _x3) {
|
|
103
|
+
return _ref3.apply(this, arguments);
|
|
104
|
+
};
|
|
105
|
+
}();
|
|
106
|
+
/**
|
|
107
|
+
* Returns a DependencyTree that includes the versions of all packages
|
|
108
|
+
* including their dependencies within the project.
|
|
109
|
+
*
|
|
110
|
+
* @returns A DependencyTree with the versions of all dependencies
|
|
111
|
+
*/
|
|
112
|
+
const getProjectDependencyTree = exports.getProjectDependencyTree = /*#__PURE__*/function () {
|
|
113
|
+
var _ref5 = _asyncToGenerator(function* () {
|
|
114
|
+
// When executing this inside template-retail-react-app, the output of `npm ls` exceeds the
|
|
115
|
+
// max buffer size that child_process can handle, so we can't use that directly. The max string
|
|
116
|
+
// size is much larger, so writing/reading a temp file is a functional workaround.
|
|
117
|
+
const tmpDir = yield (0, _fsExtra.mkdtemp)(_path.default.join(_os.default.tmpdir(), 'pwa-kit-dev-'));
|
|
118
|
+
const destination = _path.default.join(tmpDir, 'npm-ls.json');
|
|
119
|
+
try {
|
|
120
|
+
(0, _child_process.execSync)(`npm ls --all --json > ${destination}`);
|
|
121
|
+
return yield (0, _fsExtra.readJson)(destination, 'utf8');
|
|
122
|
+
} catch (_) {
|
|
123
|
+
// Don't prevent bundles from being pushed if this step fails
|
|
124
|
+
return null;
|
|
125
|
+
} finally {
|
|
126
|
+
// Remove temp file asynchronously after returning; ignore failures
|
|
127
|
+
void (0, _fsExtra.rm)(destination).catch(() => {});
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
return function getProjectDependencyTree() {
|
|
131
|
+
return _ref5.apply(this, arguments);
|
|
132
|
+
};
|
|
133
|
+
}();
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Returns the lowest version of a package installed.
|
|
137
|
+
*
|
|
138
|
+
* @param packageName - The name of the package to get the lowest version for
|
|
139
|
+
* @param dependencyTree - The dependency tree including all package versions
|
|
140
|
+
* @returns The lowest version of the given package that is installed
|
|
141
|
+
*/
|
|
142
|
+
const getLowestPackageVersion = (packageName, dependencyTree) => {
|
|
143
|
+
let lowestVersion = null;
|
|
144
|
+
function search(tree) {
|
|
145
|
+
for (const key in tree.dependencies) {
|
|
146
|
+
const dependency = tree.dependencies[key];
|
|
147
|
+
if (key === packageName) {
|
|
148
|
+
const version = dependency.version;
|
|
149
|
+
if (!lowestVersion || _semver.default.lt(version, lowestVersion)) {
|
|
150
|
+
lowestVersion = version;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (dependency.dependencies) {
|
|
154
|
+
search(dependency);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
search(dependencyTree);
|
|
159
|
+
return lowestVersion ?? 'unknown';
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Returns the versions of all PWA Kit dependencies of a project.
|
|
164
|
+
* This will search the dependency tree for the lowest version of each PWA Kit package.
|
|
165
|
+
*
|
|
166
|
+
* @param dependencyTree - The dependency tree including all package versions
|
|
167
|
+
* @returns The versions of all dependencies of the project.
|
|
168
|
+
*/
|
|
169
|
+
exports.getLowestPackageVersion = getLowestPackageVersion;
|
|
170
|
+
const getPwaKitDependencies = dependencyTree => {
|
|
171
|
+
const pwaKitDependencies = ['@salesforce/pwa-kit-react-sdk', '@salesforce/pwa-kit-runtime', '@salesforce/pwa-kit-dev'];
|
|
172
|
+
|
|
173
|
+
// pwa-kit package versions are not always listed as direct dependencies
|
|
174
|
+
// in the package.json such as when a bundle is using template extensibility
|
|
175
|
+
const nestedPwaKitDependencies = {};
|
|
176
|
+
pwaKitDependencies.forEach(packageName => {
|
|
177
|
+
nestedPwaKitDependencies[packageName] = getLowestPackageVersion(packageName, dependencyTree);
|
|
178
|
+
});
|
|
179
|
+
return nestedPwaKitDependencies;
|
|
180
|
+
};
|
|
181
|
+
exports.getPwaKitDependencies = getPwaKitDependencies;
|
|
182
|
+
class CloudAPIClient {
|
|
183
|
+
constructor(params) {
|
|
184
|
+
this.opts = {
|
|
185
|
+
origin: params.origin || DEFAULT_CLOUD_ORIGIN,
|
|
186
|
+
fetch: params.fetch || _nodeFetch.default,
|
|
187
|
+
credentials: params.credentials
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
getAuthHeader() {
|
|
191
|
+
const {
|
|
192
|
+
username,
|
|
193
|
+
api_key
|
|
194
|
+
} = this.opts.credentials;
|
|
195
|
+
const encoded = Buffer.from(`${username}:${api_key}`, 'binary').toString('base64');
|
|
196
|
+
return {
|
|
197
|
+
Authorization: `Basic ${encoded}`
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
getHeaders() {
|
|
201
|
+
var _this = this;
|
|
202
|
+
return _asyncToGenerator(function* () {
|
|
203
|
+
const pkg = yield getPkgJSON();
|
|
204
|
+
return _objectSpread({
|
|
205
|
+
'User-Agent': `${pkg.name}@${pkg.version}`
|
|
206
|
+
}, _this.getAuthHeader());
|
|
207
|
+
})();
|
|
208
|
+
}
|
|
209
|
+
throwForStatus(res) {
|
|
210
|
+
return _asyncToGenerator(function* () {
|
|
211
|
+
if (res.status < 400) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const body = yield res.text();
|
|
215
|
+
let error;
|
|
216
|
+
try {
|
|
217
|
+
error = JSON.parse(body);
|
|
218
|
+
} catch {
|
|
219
|
+
error = {}; // Cloud doesn't always return JSON
|
|
220
|
+
}
|
|
221
|
+
if (res.status === 403) {
|
|
222
|
+
error.docs_url = 'https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/mrt-overview.html#users,-abilities,-and-roles';
|
|
223
|
+
}
|
|
224
|
+
throw new Error([`HTTP ${res.status}`, error.message || body, `For more information visit ${error.docs_url || DEFAULT_DOCS_URL}`].join('\n'));
|
|
225
|
+
})();
|
|
226
|
+
}
|
|
227
|
+
push(bundle, projectSlug, target) {
|
|
228
|
+
var _this2 = this;
|
|
229
|
+
return _asyncToGenerator(function* () {
|
|
230
|
+
const base = `api/projects/${projectSlug}/builds/`;
|
|
231
|
+
const pathname = target ? base + `${target}/` : base;
|
|
232
|
+
const url = new _url.URL(_this2.opts.origin);
|
|
233
|
+
url.pathname = pathname;
|
|
234
|
+
const body = Buffer.from(JSON.stringify(bundle));
|
|
235
|
+
const headers = _objectSpread(_objectSpread({}, yield _this2.getHeaders()), {}, {
|
|
236
|
+
'Content-Length': body.length.toString()
|
|
237
|
+
});
|
|
238
|
+
const res = yield _this2.opts.fetch(url.toString(), {
|
|
239
|
+
body,
|
|
240
|
+
method: 'POST',
|
|
241
|
+
headers
|
|
242
|
+
});
|
|
243
|
+
yield _this2.throwForStatus(res);
|
|
244
|
+
return yield res.json();
|
|
245
|
+
})();
|
|
246
|
+
}
|
|
247
|
+
createLoggingToken(project, environment) {
|
|
248
|
+
var _this3 = this;
|
|
249
|
+
return _asyncToGenerator(function* () {
|
|
250
|
+
const url = new _url.URL(_this3.opts.origin);
|
|
251
|
+
url.pathname = `/api/projects/${project}/target/${environment}/jwt/`;
|
|
252
|
+
const headers = _objectSpread(_objectSpread({}, yield _this3.getHeaders()), {}, {
|
|
253
|
+
// Annoyingly, the new logging endpoint only accepts an
|
|
254
|
+
// Authorization header that is inconsistent with our older APIs!
|
|
255
|
+
Authorization: `Bearer ${_this3.opts.credentials.api_key}`
|
|
256
|
+
});
|
|
257
|
+
const res = yield _this3.opts.fetch(url.toString(), {
|
|
258
|
+
method: 'POST',
|
|
259
|
+
headers
|
|
260
|
+
});
|
|
261
|
+
yield _this3.throwForStatus(res);
|
|
262
|
+
const data = yield res.json();
|
|
263
|
+
return data['token'];
|
|
264
|
+
})();
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** Polls MRT for deployment status every 30 seconds. */
|
|
268
|
+
waitForDeploy(project, environment) {
|
|
269
|
+
var _this4 = this;
|
|
270
|
+
return _asyncToGenerator(function* () {
|
|
271
|
+
return new Promise((resolve, reject) => {
|
|
272
|
+
/** Milliseconds to wait between checks. */
|
|
273
|
+
const delay = 30_000;
|
|
274
|
+
/** Check the deployment status to see whether it has finished. */
|
|
275
|
+
const check = /*#__PURE__*/function () {
|
|
276
|
+
var _ref6 = _asyncToGenerator(function* () {
|
|
277
|
+
const url = new _url.URL(`/api/projects/${project}/target/${environment}`, _this4.opts.origin);
|
|
278
|
+
const res = yield _this4.opts.fetch(url, {
|
|
279
|
+
headers: yield _this4.getHeaders()
|
|
280
|
+
});
|
|
281
|
+
if (!res.ok) {
|
|
282
|
+
var _json;
|
|
283
|
+
const text = yield res.text();
|
|
284
|
+
let json;
|
|
285
|
+
try {
|
|
286
|
+
if (text) json = JSON.parse(text);
|
|
287
|
+
} catch (_) {} // eslint-disable-line no-empty
|
|
288
|
+
const message = ((_json = json) === null || _json === void 0 ? void 0 : _json.detail) ?? text;
|
|
289
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
290
|
+
const detail = message ? `: ${message}` : '';
|
|
291
|
+
throw new Error(`${res.status} ${res.statusText}${detail}`);
|
|
292
|
+
}
|
|
293
|
+
const data = yield res.json();
|
|
294
|
+
if (typeof data.state !== 'string') {
|
|
295
|
+
return reject(new Error('An unknown state occurred when polling the deployment.'));
|
|
296
|
+
}
|
|
297
|
+
switch (data.state) {
|
|
298
|
+
case 'CREATE_IN_PROGRESS':
|
|
299
|
+
case 'PUBLISH_IN_PROGRESS':
|
|
300
|
+
// In progress - check again after the next delay
|
|
301
|
+
// `check` is async, so we need to use .catch to properly handle errors
|
|
302
|
+
setTimeout(() => void check().catch(reject), delay);
|
|
303
|
+
return;
|
|
304
|
+
case 'CREATE_FAILED':
|
|
305
|
+
case 'PUBLISH_FAILED':
|
|
306
|
+
// Failed - reject with failure
|
|
307
|
+
return reject(new Error('Deployment failed.'));
|
|
308
|
+
case 'ACTIVE':
|
|
309
|
+
// Success!
|
|
310
|
+
return resolve();
|
|
311
|
+
default:
|
|
312
|
+
// Unknown - reject with confusion
|
|
313
|
+
return reject(new Error(`Unknown deployment state "${data.state}".`));
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
return function check() {
|
|
317
|
+
return _ref6.apply(this, arguments);
|
|
318
|
+
};
|
|
319
|
+
}();
|
|
320
|
+
// Start checking after the first delay!
|
|
321
|
+
setTimeout(() => void check().catch(reject), delay);
|
|
322
|
+
});
|
|
323
|
+
})();
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
exports.CloudAPIClient = CloudAPIClient;
|
|
327
|
+
const defaultMessage = (gitInstance = _gitRevSync.default) => {
|
|
328
|
+
try {
|
|
329
|
+
return `${gitInstance.branch()}: ${gitInstance.short()}`;
|
|
330
|
+
} catch (err) {
|
|
331
|
+
if ((err === null || err === void 0 ? void 0 : err.code) === 'ENOENT') {
|
|
332
|
+
console.log('Using default bundle message as no message was provided and not in a Git repo.');
|
|
333
|
+
}
|
|
334
|
+
return 'PWA Kit Bundle';
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
exports.defaultMessage = defaultMessage;
|
|
338
|
+
const createBundle = exports.createBundle = /*#__PURE__*/function () {
|
|
339
|
+
var _ref7 = _asyncToGenerator(function* ({
|
|
340
|
+
message,
|
|
341
|
+
ssr_parameters,
|
|
342
|
+
ssr_only,
|
|
343
|
+
ssr_shared,
|
|
344
|
+
buildDirectory,
|
|
345
|
+
projectSlug
|
|
346
|
+
}) {
|
|
347
|
+
message = message || defaultMessage();
|
|
348
|
+
const tmpDir = yield (0, _fsExtra.mkdtemp)(_path.default.join(_os.default.tmpdir(), 'pwa-kit-dev-'));
|
|
349
|
+
const destination = _path.default.join(tmpDir, 'build.tar');
|
|
350
|
+
const filesInArchive = [];
|
|
351
|
+
let bundle_metadata = {};
|
|
352
|
+
if (ssr_only.length === 0 || ssr_shared.length === 0) {
|
|
353
|
+
throw new Error('no ssrOnly or ssrShared files are defined');
|
|
354
|
+
}
|
|
355
|
+
return Promise.resolve().then(() => (0, _fsExtra.stat)(buildDirectory)).catch(() => {
|
|
356
|
+
const fullPath = _path.default.join(process.cwd(), buildDirectory);
|
|
357
|
+
throw new Error(`Build directory at path "${fullPath}" not found.\n` + 'Run `pwa-kit-dev build` first!');
|
|
358
|
+
}).then(() => new Promise((resolve, reject) => {
|
|
359
|
+
const output = (0, _fsExtra.createWriteStream)(destination);
|
|
360
|
+
const archive = (0, _archiver.default)('tar');
|
|
361
|
+
archive.pipe(output);
|
|
362
|
+
|
|
363
|
+
// See https://web.archive.org/web/20160712064705/http://archiverjs.com/docs/global.html#TarEntryData
|
|
364
|
+
const newRoot = _path.default.join(projectSlug, 'bld', '');
|
|
365
|
+
// WARNING: There are a lot of type assertions here because we use a very old
|
|
366
|
+
// version of archiver, and the types provided don't match the docs. :\
|
|
367
|
+
archive.directory(buildDirectory, '', entry => {
|
|
368
|
+
const stats = entry.stats;
|
|
369
|
+
if (stats !== null && stats !== void 0 && stats.isFile() && entry.name) {
|
|
370
|
+
filesInArchive.push(entry.name);
|
|
371
|
+
}
|
|
372
|
+
entry.prefix = newRoot;
|
|
373
|
+
return entry;
|
|
374
|
+
});
|
|
375
|
+
archive.on('error', reject);
|
|
376
|
+
output.on('finish', resolve);
|
|
377
|
+
archive.finalize();
|
|
378
|
+
})).then( /*#__PURE__*/_asyncToGenerator(function* () {
|
|
379
|
+
const {
|
|
380
|
+
dependencies = {},
|
|
381
|
+
devDependencies = {},
|
|
382
|
+
ccExtensibility = {
|
|
383
|
+
extends: '',
|
|
384
|
+
overridesDir: ''
|
|
385
|
+
}
|
|
386
|
+
} = yield getProjectPkg();
|
|
387
|
+
const extendsTemplate = 'node_modules/' + ccExtensibility.extends;
|
|
388
|
+
let cc_overrides = [];
|
|
389
|
+
if (ccExtensibility.overridesDir) {
|
|
390
|
+
const overrides_files = yield walkDir(ccExtensibility.overridesDir, ccExtensibility.overridesDir);
|
|
391
|
+
cc_overrides = Array.from(overrides_files).filter(item => (0, _fsExtra.existsSync)(_path.default.join(extendsTemplate, item)));
|
|
392
|
+
}
|
|
393
|
+
const dependencyTree = yield getProjectDependencyTree();
|
|
394
|
+
// If we can't load the dependency tree, pretend that it's empty.
|
|
395
|
+
// TODO: Should we report an error?
|
|
396
|
+
const pwaKitDeps = dependencyTree ? getPwaKitDependencies(dependencyTree) : {};
|
|
397
|
+
bundle_metadata = {
|
|
398
|
+
dependencies: _objectSpread(_objectSpread(_objectSpread({}, dependencies), devDependencies), pwaKitDeps ?? {}),
|
|
399
|
+
cc_overrides: cc_overrides
|
|
400
|
+
};
|
|
401
|
+
})).then(() => (0, _fsExtra.readFile)(destination)).then(data => {
|
|
402
|
+
const encoding = 'base64';
|
|
403
|
+
return {
|
|
404
|
+
message,
|
|
405
|
+
encoding,
|
|
406
|
+
data: data.toString(encoding),
|
|
407
|
+
ssr_parameters,
|
|
408
|
+
ssr_only: filesInArchive.filter(glob(ssr_only)),
|
|
409
|
+
ssr_shared: filesInArchive.filter(glob(ssr_shared)),
|
|
410
|
+
bundle_metadata
|
|
411
|
+
};
|
|
412
|
+
})
|
|
413
|
+
// This is a false positive. The promise returned by `.finally()` won't resolve until
|
|
414
|
+
// the `rm()` completes!
|
|
415
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
416
|
+
.finally(() => (0, _fsExtra.rm)(tmpDir, {
|
|
417
|
+
recursive: true
|
|
418
|
+
}));
|
|
419
|
+
});
|
|
420
|
+
return function createBundle(_x5) {
|
|
421
|
+
return _ref7.apply(this, arguments);
|
|
422
|
+
};
|
|
423
|
+
}();
|
|
424
|
+
const glob = patterns => {
|
|
425
|
+
// The patterns can include negations, so matching is done against all
|
|
426
|
+
// the patterns. A match is true if a given path matches any pattern and
|
|
427
|
+
// does not match any negating patterns.
|
|
428
|
+
|
|
429
|
+
const allPatterns = (patterns || []).map(pattern => new _minimatch.Minimatch(pattern, {
|
|
430
|
+
nocomment: true
|
|
431
|
+
})).filter(pattern => !pattern.empty);
|
|
432
|
+
const positivePatterns = allPatterns.filter(pattern => !pattern.negate);
|
|
433
|
+
const negativePatterns = allPatterns.filter(pattern => pattern.negate);
|
|
434
|
+
return path => {
|
|
435
|
+
if (path) {
|
|
436
|
+
const positive = positivePatterns.some(pattern => pattern.match(path));
|
|
437
|
+
const negative = negativePatterns.some(pattern => !pattern.match(path));
|
|
438
|
+
return positive && !negative;
|
|
439
|
+
}
|
|
440
|
+
return false;
|
|
441
|
+
};
|
|
442
|
+
};
|
|
443
|
+
exports.glob = glob;
|
|
444
|
+
const getCredentialsFile = (cloudOrigin, credentialsFile) => {
|
|
445
|
+
if (credentialsFile) {
|
|
446
|
+
return credentialsFile;
|
|
447
|
+
} else {
|
|
448
|
+
const url = new _url.URL(cloudOrigin);
|
|
449
|
+
const host = url.host;
|
|
450
|
+
const suffix = host === 'cloud.mobify.com' ? '' : `--${host}`;
|
|
451
|
+
return _path.default.join(_os.default.homedir(), `.mobify${suffix}`);
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
exports.getCredentialsFile = getCredentialsFile;
|
|
455
|
+
const readCredentials = exports.readCredentials = /*#__PURE__*/function () {
|
|
456
|
+
var _ref9 = _asyncToGenerator(function* (filepath) {
|
|
457
|
+
try {
|
|
458
|
+
const data = yield (0, _fsExtra.readJson)(filepath);
|
|
459
|
+
return {
|
|
460
|
+
username: data.username,
|
|
461
|
+
api_key: data.api_key
|
|
462
|
+
};
|
|
463
|
+
} catch (e) {
|
|
464
|
+
throw new Error(`Credentials file "${filepath}" not found.\n` + 'Visit https://runtime.commercecloud.com/account/settings for ' + 'steps on authorizing your computer to push bundles.');
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
return function readCredentials(_x6) {
|
|
468
|
+
return _ref9.apply(this, arguments);
|
|
469
|
+
};
|
|
470
|
+
}();
|
|
471
|
+
const parseLog = log => {
|
|
472
|
+
const parts = log.trim().split('\t');
|
|
473
|
+
let requestId, shortRequestId, level;
|
|
474
|
+
if (parts.length >= 3 && _validator.default.isISO8601(parts[0]) && _validator.default.isUUID(parts[1]) && _validator.default.isAlpha(parts[2])) {
|
|
475
|
+
// An application log
|
|
476
|
+
parts.shift();
|
|
477
|
+
requestId = parts.shift();
|
|
478
|
+
level = parts.shift();
|
|
479
|
+
} else {
|
|
480
|
+
// A platform log
|
|
481
|
+
const words = parts[0].split(' ');
|
|
482
|
+
level = words.shift();
|
|
483
|
+
parts[0] = words.join(' ');
|
|
484
|
+
}
|
|
485
|
+
const message = parts.join('\t');
|
|
486
|
+
const match = /(?<id>[a-f\d]{8})/.exec(requestId || message);
|
|
487
|
+
if (match) {
|
|
488
|
+
var _match$groups;
|
|
489
|
+
shortRequestId = (_match$groups = match.groups) === null || _match$groups === void 0 ? void 0 : _match$groups.id;
|
|
490
|
+
}
|
|
491
|
+
return {
|
|
492
|
+
level,
|
|
493
|
+
message,
|
|
494
|
+
shortRequestId
|
|
495
|
+
};
|
|
496
|
+
};
|
|
497
|
+
exports.parseLog = parseLog;
|