@angular-devkit/build-angular 14.1.3 → 14.2.0-next.2
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 +25 -25
- package/src/builders/browser-esbuild/compiler-plugin.js +1 -1
- package/src/builders/browser-esbuild/sass-plugin.d.ts +1 -1
- package/src/builders/browser-esbuild/sass-plugin.js +71 -28
- package/src/builders/browser-esbuild/stylesheets.js +7 -4
- package/src/builders/dev-server/index.js +12 -2
- package/src/utils/service-worker.d.ts +3 -1
- package/src/utils/service-worker.js +33 -23
- package/src/webpack/configs/dev-server.js +0 -17
- package/src/webpack/plugins/esbuild-executor.d.ts +1 -1
- package/src/webpack/plugins/service-worker-plugin.d.ts +20 -0
- package/src/webpack/plugins/service-worker-plugin.js +27 -0
package/package.json
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-devkit/build-angular",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.2.0-next.2",
|
|
4
4
|
"description": "Angular Webpack Build Facade",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"typings": "src/index.d.ts",
|
|
7
7
|
"builders": "builders.json",
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@ampproject/remapping": "2.2.0",
|
|
10
|
-
"@angular-devkit/architect": "0.
|
|
11
|
-
"@angular-devkit/build-webpack": "0.
|
|
12
|
-
"@angular-devkit/core": "14.
|
|
13
|
-
"@babel/core": "7.18.
|
|
14
|
-
"@babel/generator": "7.18.
|
|
10
|
+
"@angular-devkit/architect": "0.1402.0-next.2",
|
|
11
|
+
"@angular-devkit/build-webpack": "0.1402.0-next.2",
|
|
12
|
+
"@angular-devkit/core": "14.2.0-next.2",
|
|
13
|
+
"@babel/core": "7.18.10",
|
|
14
|
+
"@babel/generator": "7.18.12",
|
|
15
15
|
"@babel/helper-annotate-as-pure": "7.18.6",
|
|
16
|
-
"@babel/plugin-proposal-async-generator-functions": "7.18.
|
|
16
|
+
"@babel/plugin-proposal-async-generator-functions": "7.18.10",
|
|
17
17
|
"@babel/plugin-transform-async-to-generator": "7.18.6",
|
|
18
|
-
"@babel/plugin-transform-runtime": "7.18.
|
|
19
|
-
"@babel/preset-env": "7.18.
|
|
20
|
-
"@babel/runtime": "7.18.
|
|
21
|
-
"@babel/template": "7.18.
|
|
18
|
+
"@babel/plugin-transform-runtime": "7.18.10",
|
|
19
|
+
"@babel/preset-env": "7.18.10",
|
|
20
|
+
"@babel/runtime": "7.18.9",
|
|
21
|
+
"@babel/template": "7.18.10",
|
|
22
22
|
"@discoveryjs/json-ext": "0.5.7",
|
|
23
|
-
"@ngtools/webpack": "14.
|
|
23
|
+
"@ngtools/webpack": "14.2.0-next.2",
|
|
24
24
|
"ansi-colors": "4.1.3",
|
|
25
25
|
"babel-loader": "8.2.5",
|
|
26
26
|
"babel-plugin-istanbul": "6.1.1",
|
|
27
27
|
"browserslist": "^4.9.1",
|
|
28
|
-
"cacache": "16.1.
|
|
28
|
+
"cacache": "16.1.2",
|
|
29
29
|
"copy-webpack-plugin": "11.0.0",
|
|
30
30
|
"critters": "0.0.16",
|
|
31
31
|
"css-loader": "6.7.1",
|
|
32
|
-
"esbuild-wasm": "0.
|
|
32
|
+
"esbuild-wasm": "0.15.5",
|
|
33
33
|
"glob": "8.0.3",
|
|
34
34
|
"https-proxy-agent": "5.0.1",
|
|
35
35
|
"inquirer": "8.2.4",
|
|
@@ -45,39 +45,39 @@
|
|
|
45
45
|
"ora": "5.4.1",
|
|
46
46
|
"parse5-html-rewriting-stream": "6.0.1",
|
|
47
47
|
"piscina": "3.2.0",
|
|
48
|
-
"postcss": "8.4.
|
|
48
|
+
"postcss": "8.4.16",
|
|
49
49
|
"postcss-import": "14.1.0",
|
|
50
50
|
"postcss-loader": "7.0.1",
|
|
51
|
-
"postcss-preset-env": "7.
|
|
51
|
+
"postcss-preset-env": "7.8.0",
|
|
52
52
|
"regenerator-runtime": "0.13.9",
|
|
53
53
|
"resolve-url-loader": "5.0.0",
|
|
54
54
|
"rxjs": "6.6.7",
|
|
55
|
-
"sass": "1.
|
|
55
|
+
"sass": "1.54.4",
|
|
56
56
|
"sass-loader": "13.0.2",
|
|
57
57
|
"semver": "7.3.7",
|
|
58
58
|
"source-map-loader": "4.0.0",
|
|
59
59
|
"source-map-support": "0.5.21",
|
|
60
|
-
"stylus": "0.
|
|
60
|
+
"stylus": "0.59.0",
|
|
61
61
|
"stylus-loader": "7.0.0",
|
|
62
62
|
"terser": "5.14.2",
|
|
63
63
|
"text-table": "0.2.0",
|
|
64
64
|
"tree-kill": "1.2.2",
|
|
65
65
|
"tslib": "2.4.0",
|
|
66
|
-
"webpack": "5.
|
|
66
|
+
"webpack": "5.74.0",
|
|
67
67
|
"webpack-dev-middleware": "5.3.3",
|
|
68
|
-
"webpack-dev-server": "4.
|
|
68
|
+
"webpack-dev-server": "4.10.0",
|
|
69
69
|
"webpack-merge": "5.8.0",
|
|
70
70
|
"webpack-subresource-integrity": "5.1.0"
|
|
71
71
|
},
|
|
72
72
|
"optionalDependencies": {
|
|
73
|
-
"esbuild": "0.
|
|
73
|
+
"esbuild": "0.15.5"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
|
-
"@angular/compiler-cli": "^14.0.0",
|
|
77
|
-
"@angular/localize": "^14.0.0",
|
|
78
|
-
"@angular/service-worker": "^14.0.0",
|
|
76
|
+
"@angular/compiler-cli": "^14.0.0 || ^14.0.0-next || ^14.1.0-next",
|
|
77
|
+
"@angular/localize": "^14.0.0 || ^14.0.0-next || ^14.1.0-next",
|
|
78
|
+
"@angular/service-worker": "^14.0.0 || ^14.0.0-next || ^14.1.0-next",
|
|
79
79
|
"karma": "^6.3.0",
|
|
80
|
-
"ng-packagr": "^14.0.0",
|
|
80
|
+
"ng-packagr": "^14.0.0 || ^14.0.0-next || ^14.1.0-next",
|
|
81
81
|
"protractor": "^7.0.0",
|
|
82
82
|
"tailwindcss": "^2.0.0 || ^3.0.0",
|
|
83
83
|
"typescript": ">=4.6.2 <4.8"
|
|
@@ -208,7 +208,7 @@ function createCompilerPlugin(pluginOptions, styleOptions) {
|
|
|
208
208
|
// Create the Angular specific program that contains the Angular compiler
|
|
209
209
|
const angularProgram = new compilerCli.NgtscProgram(rootNames, compilerOptions, host);
|
|
210
210
|
const angularCompiler = angularProgram.compiler;
|
|
211
|
-
const { ignoreForDiagnostics
|
|
211
|
+
const { ignoreForDiagnostics } = angularCompiler;
|
|
212
212
|
const typeScriptProgram = angularProgram.getTsProgram();
|
|
213
213
|
const builder = typescript_1.default.createAbstractBuilder(typeScriptProgram, host);
|
|
214
214
|
await angularCompiler.analyzeAsync();
|
|
@@ -6,47 +6,90 @@
|
|
|
6
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
7
7
|
* found in the LICENSE file at https://angular.io/license
|
|
8
8
|
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
9
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
33
|
exports.createSassPlugin = void 0;
|
|
11
|
-
const
|
|
34
|
+
const url_1 = require("url");
|
|
12
35
|
function createSassPlugin(options) {
|
|
13
36
|
return {
|
|
14
37
|
name: 'angular-sass',
|
|
15
38
|
setup(build) {
|
|
16
39
|
let sass;
|
|
17
|
-
build.onStart(() => {
|
|
18
|
-
|
|
40
|
+
build.onStart(async () => {
|
|
41
|
+
// Lazily load Sass
|
|
42
|
+
sass = await Promise.resolve().then(() => __importStar(require('sass')));
|
|
19
43
|
});
|
|
20
|
-
build.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
includePaths: options.includePaths,
|
|
28
|
-
indentedSyntax: args.path.endsWith('.sass'),
|
|
29
|
-
outputStyle: 'expanded',
|
|
44
|
+
build.onLoad({ filter: /\.s[ac]ss$/ }, (args) => {
|
|
45
|
+
try {
|
|
46
|
+
const warnings = [];
|
|
47
|
+
// Use sync version as async version is slower.
|
|
48
|
+
const { css, sourceMap, loadedUrls } = sass.compile(args.path, {
|
|
49
|
+
style: 'expanded',
|
|
50
|
+
loadPaths: options.loadPaths,
|
|
30
51
|
sourceMap: options.sourcemap,
|
|
31
|
-
|
|
32
|
-
sourceMapEmbed: options.sourcemap,
|
|
52
|
+
sourceMapIncludeSources: options.sourcemap,
|
|
33
53
|
quietDeps: true,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
54
|
+
logger: {
|
|
55
|
+
warn: (text, _options) => {
|
|
56
|
+
warnings.push({
|
|
57
|
+
text,
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
},
|
|
41
61
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
62
|
+
return {
|
|
63
|
+
loader: 'css',
|
|
64
|
+
contents: `${css}\n${sourceMapToUrlComment(sourceMap)}`,
|
|
65
|
+
watchFiles: loadedUrls.map((url) => (0, url_1.fileURLToPath)(url)),
|
|
66
|
+
warnings,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (error instanceof sass.Exception) {
|
|
71
|
+
const file = error.span.url ? (0, url_1.fileURLToPath)(error.span.url) : undefined;
|
|
72
|
+
return {
|
|
73
|
+
loader: 'css',
|
|
74
|
+
errors: [
|
|
75
|
+
{
|
|
76
|
+
text: error.toString(),
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
watchFiles: file ? [file] : undefined,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
48
84
|
});
|
|
49
85
|
},
|
|
50
86
|
};
|
|
51
87
|
}
|
|
52
88
|
exports.createSassPlugin = createSassPlugin;
|
|
89
|
+
function sourceMapToUrlComment(sourceMap) {
|
|
90
|
+
if (!sourceMap) {
|
|
91
|
+
return '';
|
|
92
|
+
}
|
|
93
|
+
const urlSourceMap = Buffer.from(JSON.stringify(sourceMap), 'utf-8').toString('base64');
|
|
94
|
+
return `/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${urlSourceMap} */`;
|
|
95
|
+
}
|
|
@@ -36,14 +36,17 @@ const css_resource_plugin_1 = require("./css-resource-plugin");
|
|
|
36
36
|
const esbuild_1 = require("./esbuild");
|
|
37
37
|
const sass_plugin_1 = require("./sass-plugin");
|
|
38
38
|
async function bundleStylesheet(entry, options) {
|
|
39
|
-
var _a, _b;
|
|
39
|
+
var _a, _b, _c;
|
|
40
|
+
const loadPaths = (_a = options.includePaths) !== null && _a !== void 0 ? _a : [];
|
|
41
|
+
// Needed to resolve node packages.
|
|
42
|
+
loadPaths.push(path.join(options.workspaceRoot, 'node_modules'));
|
|
40
43
|
// Execute esbuild
|
|
41
44
|
const result = await (0, esbuild_1.bundle)({
|
|
42
45
|
...entry,
|
|
43
46
|
absWorkingDir: options.workspaceRoot,
|
|
44
47
|
bundle: true,
|
|
45
|
-
entryNames: (
|
|
46
|
-
assetNames: (
|
|
48
|
+
entryNames: (_b = options.outputNames) === null || _b === void 0 ? void 0 : _b.bundles,
|
|
49
|
+
assetNames: (_c = options.outputNames) === null || _c === void 0 ? void 0 : _c.media,
|
|
47
50
|
logLevel: 'silent',
|
|
48
51
|
minify: options.optimization,
|
|
49
52
|
sourcemap: options.sourcemap,
|
|
@@ -55,7 +58,7 @@ async function bundleStylesheet(entry, options) {
|
|
|
55
58
|
conditions: ['style', 'sass'],
|
|
56
59
|
mainFields: ['style', 'sass'],
|
|
57
60
|
plugins: [
|
|
58
|
-
(0, sass_plugin_1.createSassPlugin)({ sourcemap: !!options.sourcemap,
|
|
61
|
+
(0, sass_plugin_1.createSassPlugin)({ sourcemap: !!options.sourcemap, loadPaths }),
|
|
59
62
|
(0, css_resource_plugin_1.createCssResourcePlugin)(),
|
|
60
63
|
],
|
|
61
64
|
});
|
|
@@ -51,6 +51,7 @@ const webpack_browser_config_1 = require("../../utils/webpack-browser-config");
|
|
|
51
51
|
const webpack_diagnostics_1 = require("../../utils/webpack-diagnostics");
|
|
52
52
|
const configs_1 = require("../../webpack/configs");
|
|
53
53
|
const index_html_webpack_plugin_1 = require("../../webpack/plugins/index-html-webpack-plugin");
|
|
54
|
+
const service_worker_plugin_1 = require("../../webpack/plugins/service-worker-plugin");
|
|
54
55
|
const stats_1 = require("../../webpack/utils/stats");
|
|
55
56
|
const schema_1 = require("../browser/schema");
|
|
56
57
|
/**
|
|
@@ -160,6 +161,7 @@ function serveWebpackBrowser(options, context, transforms = {}) {
|
|
|
160
161
|
if (transforms.webpackConfiguration) {
|
|
161
162
|
webpackConfig = await transforms.webpackConfiguration(webpackConfig);
|
|
162
163
|
}
|
|
164
|
+
(_c = webpackConfig.plugins) !== null && _c !== void 0 ? _c : (webpackConfig.plugins = []);
|
|
163
165
|
if (browserOptions.index) {
|
|
164
166
|
const { scripts = [], styles = [], baseHref } = browserOptions;
|
|
165
167
|
const entrypoints = (0, package_chunk_sort_1.generateEntryPoints)({
|
|
@@ -168,9 +170,8 @@ function serveWebpackBrowser(options, context, transforms = {}) {
|
|
|
168
170
|
// The below is needed as otherwise HMR for CSS will break.
|
|
169
171
|
// styles.js and runtime.js needs to be loaded as a non-module scripts as otherwise `document.currentScript` will be null.
|
|
170
172
|
// https://github.com/webpack-contrib/mini-css-extract-plugin/blob/90445dd1d81da0c10b9b0e8a17b417d0651816b8/src/hmr/hotModuleReplacement.js#L39
|
|
171
|
-
isHMREnabled: !!((
|
|
173
|
+
isHMREnabled: !!((_d = webpackConfig.devServer) === null || _d === void 0 ? void 0 : _d.hot),
|
|
172
174
|
});
|
|
173
|
-
(_d = webpackConfig.plugins) !== null && _d !== void 0 ? _d : (webpackConfig.plugins = []);
|
|
174
175
|
webpackConfig.plugins.push(new index_html_webpack_plugin_1.IndexHtmlWebpackPlugin({
|
|
175
176
|
indexPath: path.resolve(workspaceRoot, (0, webpack_browser_config_1.getIndexInputFile)(browserOptions.index)),
|
|
176
177
|
outputPath: (0, webpack_browser_config_1.getIndexOutputFile)(browserOptions.index),
|
|
@@ -185,6 +186,15 @@ function serveWebpackBrowser(options, context, transforms = {}) {
|
|
|
185
186
|
lang: locale,
|
|
186
187
|
}));
|
|
187
188
|
}
|
|
189
|
+
if (browserOptions.serviceWorker) {
|
|
190
|
+
webpackConfig.plugins.push(new service_worker_plugin_1.ServiceWorkerPlugin({
|
|
191
|
+
baseHref: browserOptions.baseHref,
|
|
192
|
+
root: context.workspaceRoot,
|
|
193
|
+
projectRoot,
|
|
194
|
+
outputPath: path.join(context.workspaceRoot, browserOptions.outputPath),
|
|
195
|
+
ngswConfigPath: browserOptions.ngswConfigPath,
|
|
196
|
+
}));
|
|
197
|
+
}
|
|
188
198
|
return {
|
|
189
199
|
browserOptions,
|
|
190
200
|
webpackConfig,
|
|
@@ -5,4 +5,6 @@
|
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
/// <reference types="node" />
|
|
9
|
+
import { promises as fsPromises } from 'fs';
|
|
10
|
+
export declare function augmentAppWithServiceWorker(appRoot: string, workspaceRoot: string, outputPath: string, baseHref: string, ngswConfigPath?: string, inputputFileSystem?: typeof fsPromises, outputFileSystem?: typeof fsPromises): Promise<void>;
|
|
@@ -34,40 +34,42 @@ exports.augmentAppWithServiceWorker = void 0;
|
|
|
34
34
|
const crypto = __importStar(require("crypto"));
|
|
35
35
|
const fs_1 = require("fs");
|
|
36
36
|
const path = __importStar(require("path"));
|
|
37
|
-
const stream_1 = require("stream");
|
|
38
37
|
const error_1 = require("./error");
|
|
39
38
|
const load_esm_1 = require("./load-esm");
|
|
40
39
|
class CliFilesystem {
|
|
41
|
-
constructor(base) {
|
|
40
|
+
constructor(fs, base) {
|
|
41
|
+
this.fs = fs;
|
|
42
42
|
this.base = base;
|
|
43
43
|
}
|
|
44
44
|
list(dir) {
|
|
45
45
|
return this._recursiveList(this._resolve(dir), []);
|
|
46
46
|
}
|
|
47
47
|
read(file) {
|
|
48
|
-
return
|
|
48
|
+
return this.fs.readFile(this._resolve(file), 'utf-8');
|
|
49
49
|
}
|
|
50
|
-
hash(file) {
|
|
51
|
-
return
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
async hash(file) {
|
|
51
|
+
return crypto
|
|
52
|
+
.createHash('sha1')
|
|
53
|
+
.update(await this.fs.readFile(this._resolve(file)))
|
|
54
|
+
.digest('hex');
|
|
55
55
|
}
|
|
56
|
-
write(
|
|
57
|
-
|
|
56
|
+
write(_file, _content) {
|
|
57
|
+
throw new Error('This should never happen.');
|
|
58
58
|
}
|
|
59
59
|
_resolve(file) {
|
|
60
60
|
return path.join(this.base, file);
|
|
61
61
|
}
|
|
62
62
|
async _recursiveList(dir, items) {
|
|
63
63
|
const subdirectories = [];
|
|
64
|
-
for
|
|
65
|
-
|
|
64
|
+
for (const entry of await this.fs.readdir(dir)) {
|
|
65
|
+
const entryPath = path.join(dir, entry);
|
|
66
|
+
const stats = await this.fs.stat(entryPath);
|
|
67
|
+
if (stats.isFile()) {
|
|
66
68
|
// Uses posix paths since the service worker expects URLs
|
|
67
|
-
items.push('/' + path.relative(this.base,
|
|
69
|
+
items.push('/' + path.relative(this.base, entryPath).replace(/\\/g, '/'));
|
|
68
70
|
}
|
|
69
|
-
else if (
|
|
70
|
-
subdirectories.push(
|
|
71
|
+
else if (stats.isDirectory()) {
|
|
72
|
+
subdirectories.push(entryPath);
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
for (const subdirectory of subdirectories) {
|
|
@@ -76,7 +78,7 @@ class CliFilesystem {
|
|
|
76
78
|
return items;
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
|
-
async function augmentAppWithServiceWorker(appRoot, workspaceRoot, outputPath, baseHref, ngswConfigPath) {
|
|
81
|
+
async function augmentAppWithServiceWorker(appRoot, workspaceRoot, outputPath, baseHref, ngswConfigPath, inputputFileSystem = fs_1.promises, outputFileSystem = fs_1.promises) {
|
|
80
82
|
// Determine the configuration file path
|
|
81
83
|
const configPath = ngswConfigPath
|
|
82
84
|
? path.join(workspaceRoot, ngswConfigPath)
|
|
@@ -84,7 +86,7 @@ async function augmentAppWithServiceWorker(appRoot, workspaceRoot, outputPath, b
|
|
|
84
86
|
// Read the configuration file
|
|
85
87
|
let config;
|
|
86
88
|
try {
|
|
87
|
-
const configurationData = await
|
|
89
|
+
const configurationData = await inputputFileSystem.readFile(configPath, 'utf-8');
|
|
88
90
|
config = JSON.parse(configurationData);
|
|
89
91
|
}
|
|
90
92
|
catch (error) {
|
|
@@ -103,20 +105,28 @@ async function augmentAppWithServiceWorker(appRoot, workspaceRoot, outputPath, b
|
|
|
103
105
|
// changed to a direct dynamic import.
|
|
104
106
|
const GeneratorConstructor = (await (0, load_esm_1.loadEsmModule)('@angular/service-worker/config')).Generator;
|
|
105
107
|
// Generate the manifest
|
|
106
|
-
const generator = new GeneratorConstructor(new CliFilesystem(outputPath), baseHref);
|
|
108
|
+
const generator = new GeneratorConstructor(new CliFilesystem(outputFileSystem, outputPath), baseHref);
|
|
107
109
|
const output = await generator.process(config);
|
|
108
110
|
// Write the manifest
|
|
109
111
|
const manifest = JSON.stringify(output, null, 2);
|
|
110
|
-
await
|
|
112
|
+
await outputFileSystem.writeFile(path.join(outputPath, 'ngsw.json'), manifest);
|
|
111
113
|
// Find the service worker package
|
|
112
114
|
const workerPath = require.resolve('@angular/service-worker/ngsw-worker.js');
|
|
115
|
+
const copy = async (src, dest) => {
|
|
116
|
+
const resolvedDest = path.join(outputPath, dest);
|
|
117
|
+
return inputputFileSystem === outputFileSystem
|
|
118
|
+
? // Native FS (Builder).
|
|
119
|
+
inputputFileSystem.copyFile(workerPath, resolvedDest, fs_1.constants.COPYFILE_FICLONE)
|
|
120
|
+
: // memfs (Webpack): Read the file from the input FS (disk) and write it to the output FS (memory).
|
|
121
|
+
outputFileSystem.writeFile(resolvedDest, await inputputFileSystem.readFile(src));
|
|
122
|
+
};
|
|
113
123
|
// Write the worker code
|
|
114
|
-
await
|
|
124
|
+
await copy(workerPath, 'ngsw-worker.js');
|
|
115
125
|
// If present, write the safety worker code
|
|
116
|
-
const safetyPath = path.join(path.dirname(workerPath), 'safety-worker.js');
|
|
117
126
|
try {
|
|
118
|
-
|
|
119
|
-
await
|
|
127
|
+
const safetyPath = path.join(path.dirname(workerPath), 'safety-worker.js');
|
|
128
|
+
await copy(safetyPath, 'worker-basic.min.js');
|
|
129
|
+
await copy(safetyPath, 'safety-worker.js');
|
|
120
130
|
}
|
|
121
131
|
catch (error) {
|
|
122
132
|
(0, error_1.assertIsError)(error);
|
|
@@ -98,23 +98,6 @@ async function getDevServerConfig(wco) {
|
|
|
98
98
|
publicPath: servePath,
|
|
99
99
|
stats: false,
|
|
100
100
|
},
|
|
101
|
-
setupMiddlewares: (middlewares, _devServer) => {
|
|
102
|
-
// Temporary workaround for https://github.com/webpack/webpack-dev-server/issues/4180
|
|
103
|
-
middlewares.push({
|
|
104
|
-
name: 'options-request-response',
|
|
105
|
-
path: '*',
|
|
106
|
-
middleware: (req, res, next) => {
|
|
107
|
-
if (req.method === 'OPTIONS') {
|
|
108
|
-
res.statusCode = 204;
|
|
109
|
-
res.setHeader('Content-Length', 0);
|
|
110
|
-
res.end();
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
next();
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
return middlewares;
|
|
117
|
-
},
|
|
118
101
|
liveReload,
|
|
119
102
|
hot: hmr && !liveReload ? 'only' : hmr,
|
|
120
103
|
proxy: await addProxyConfig(root, proxyConfig),
|
|
@@ -41,6 +41,6 @@ export declare class EsbuildExecutor implements Pick<typeof import('esbuild'), '
|
|
|
41
41
|
* Transitions an executor instance to use the WASM-variant of esbuild.
|
|
42
42
|
*/
|
|
43
43
|
private useWasm;
|
|
44
|
-
transform(input: string, options?: TransformOptions): Promise<TransformResult>;
|
|
44
|
+
transform(input: string | Uint8Array, options?: TransformOptions): Promise<TransformResult>;
|
|
45
45
|
formatMessages(messages: PartialMessage[], options: FormatMessagesOptions): Promise<string[]>;
|
|
46
46
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
+
* found in the LICENSE file at https://angular.io/license
|
|
7
|
+
*/
|
|
8
|
+
import type { Compiler } from 'webpack';
|
|
9
|
+
export interface ServiceWorkerPluginOptions {
|
|
10
|
+
projectRoot: string;
|
|
11
|
+
root: string;
|
|
12
|
+
outputPath: string;
|
|
13
|
+
baseHref?: string;
|
|
14
|
+
ngswConfigPath?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare class ServiceWorkerPlugin {
|
|
17
|
+
private readonly options;
|
|
18
|
+
constructor(options: ServiceWorkerPluginOptions);
|
|
19
|
+
apply(compiler: Compiler): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.io/license
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ServiceWorkerPlugin = void 0;
|
|
11
|
+
const service_worker_1 = require("../../utils/service-worker");
|
|
12
|
+
class ServiceWorkerPlugin {
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this.options = options;
|
|
15
|
+
}
|
|
16
|
+
apply(compiler) {
|
|
17
|
+
compiler.hooks.done.tapPromise('angular-service-worker', async (_compilation) => {
|
|
18
|
+
const { projectRoot, root, baseHref = '', ngswConfigPath, outputPath } = this.options;
|
|
19
|
+
await (0, service_worker_1.augmentAppWithServiceWorker)(projectRoot, root, outputPath, baseHref, ngswConfigPath,
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
+
compiler.inputFileSystem.promises,
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
compiler.outputFileSystem.promises);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.ServiceWorkerPlugin = ServiceWorkerPlugin;
|