@analogjs/vite-plugin-angular 0.2.0-alpha.1 → 0.2.0-alpha.10
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 +4 -1
- package/setup-vitest.d.ts +4 -0
- package/setup-vitest.js +116 -0
- package/setup-vitest.js.map +1 -0
- package/src/lib/angular-vite-plugin.d.ts +4 -3
- package/src/lib/angular-vite-plugin.js +133 -68
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/inline-styles-plugin.d.ts +10 -0
- package/src/lib/inline-styles-plugin.js +40 -0
- package/src/lib/inline-styles-plugin.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@analogjs/vite-plugin-angular",
|
|
3
3
|
"description": "Vite Plugin for Angular",
|
|
4
|
-
"version": "0.2.0-alpha.
|
|
4
|
+
"version": "0.2.0-alpha.10",
|
|
5
5
|
"keywords": [
|
|
6
|
+
"vite",
|
|
7
|
+
"vitest",
|
|
6
8
|
"vite-plugin",
|
|
7
9
|
"angular"
|
|
8
10
|
],
|
|
@@ -18,6 +20,7 @@
|
|
|
18
20
|
},
|
|
19
21
|
"peerDependencies": {
|
|
20
22
|
"@angular-devkit/build-angular": "^14.0.0",
|
|
23
|
+
"zone.js": "~0.11.4",
|
|
21
24
|
"tslib": "^2.0.0"
|
|
22
25
|
},
|
|
23
26
|
"main": "./src/index.js",
|
package/setup-vitest.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("zone.js");
|
|
4
|
+
require("zone.js/dist/sync-test");
|
|
5
|
+
require("zone.js/dist/proxy");
|
|
6
|
+
require("zone.js/testing");
|
|
7
|
+
/**
|
|
8
|
+
* Patch Vitest's describe/test/beforeEach/afterEach functions so test code
|
|
9
|
+
* always runs in a testZone (ProxyZone).
|
|
10
|
+
*/
|
|
11
|
+
/* global Zone */
|
|
12
|
+
const Zone = globalThis['Zone'];
|
|
13
|
+
if (Zone === undefined) {
|
|
14
|
+
throw new Error('Missing: Zone (zone.js)');
|
|
15
|
+
}
|
|
16
|
+
if (globalThis['__vitest_zone_patch__'] === true) {
|
|
17
|
+
throw new Error("'vitest' has already been patched with 'Zone'.");
|
|
18
|
+
}
|
|
19
|
+
globalThis['__vitest_zone_patch__'] = true;
|
|
20
|
+
const SyncTestZoneSpec = Zone['SyncTestZoneSpec'];
|
|
21
|
+
const ProxyZoneSpec = Zone['ProxyZoneSpec'];
|
|
22
|
+
if (SyncTestZoneSpec === undefined) {
|
|
23
|
+
throw new Error('Missing: SyncTestZoneSpec (zone.js/dist/sync-test)');
|
|
24
|
+
}
|
|
25
|
+
if (ProxyZoneSpec === undefined) {
|
|
26
|
+
throw new Error('Missing: ProxyZoneSpec (zone.js/dist/proxy.js)');
|
|
27
|
+
}
|
|
28
|
+
const env = globalThis;
|
|
29
|
+
const ambientZone = Zone.current;
|
|
30
|
+
// Create a synchronous-only zone in which to run `describe` blocks in order to
|
|
31
|
+
// raise an error if any asynchronous operations are attempted
|
|
32
|
+
// inside of a `describe` but outside of a `beforeEach` or `it`.
|
|
33
|
+
const syncZone = ambientZone.fork(new SyncTestZoneSpec('vitest.describe'));
|
|
34
|
+
function wrapDescribeInZone(describeBody) {
|
|
35
|
+
return function (...args) {
|
|
36
|
+
return syncZone.run(describeBody, null, args);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// Create a proxy zone in which to run `test` blocks so that the tests function
|
|
40
|
+
// can retroactively install different zones.
|
|
41
|
+
const testProxyZone = ambientZone.fork(new ProxyZoneSpec());
|
|
42
|
+
function wrapTestInZone(testBody) {
|
|
43
|
+
if (testBody === undefined) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const wrappedFunc = function () {
|
|
47
|
+
return testProxyZone.run(testBody, null, arguments);
|
|
48
|
+
};
|
|
49
|
+
try {
|
|
50
|
+
Object.defineProperty(wrappedFunc, 'length', {
|
|
51
|
+
configurable: true,
|
|
52
|
+
writable: true,
|
|
53
|
+
enumerable: false,
|
|
54
|
+
});
|
|
55
|
+
wrappedFunc.length = testBody.length;
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
return testBody.length === 0
|
|
59
|
+
? () => testProxyZone.run(testBody, null)
|
|
60
|
+
: (done) => testProxyZone.run(testBody, null, [done]);
|
|
61
|
+
}
|
|
62
|
+
return wrappedFunc;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* bind describe method to wrap describe.each function
|
|
66
|
+
*/
|
|
67
|
+
const bindDescribe = (originalVitestFn) => function (...eachArgs) {
|
|
68
|
+
return function (...args) {
|
|
69
|
+
args[1] = wrapDescribeInZone(args[1]);
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
return originalVitestFn.apply(this, eachArgs).apply(this, args);
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* bind test method to wrap test.each function
|
|
76
|
+
*/
|
|
77
|
+
const bindTest = (originalVitestFn) => function (...eachArgs) {
|
|
78
|
+
return function (...args) {
|
|
79
|
+
args[1] = wrapTestInZone(args[1]);
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
return originalVitestFn.apply(this, eachArgs).apply(this, args);
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
['describe'].forEach((methodName) => {
|
|
85
|
+
const originalvitestFn = env[methodName];
|
|
86
|
+
env[methodName] = function (...args) {
|
|
87
|
+
args[1] = wrapDescribeInZone(args[1]);
|
|
88
|
+
return originalvitestFn.apply(this, args);
|
|
89
|
+
};
|
|
90
|
+
env[methodName].each = bindDescribe(originalvitestFn.each);
|
|
91
|
+
if (methodName === 'describe') {
|
|
92
|
+
env[methodName].only = env['fdescribe'];
|
|
93
|
+
env[methodName].skip = env['xdescribe'];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
['test', 'it'].forEach((methodName) => {
|
|
97
|
+
const originalvitestFn = env[methodName];
|
|
98
|
+
env[methodName] = function (...args) {
|
|
99
|
+
args[1] = wrapTestInZone(args[1]);
|
|
100
|
+
return originalvitestFn.apply(this, args);
|
|
101
|
+
};
|
|
102
|
+
env[methodName].each = bindTest(originalvitestFn.each);
|
|
103
|
+
if (methodName === 'test' || methodName === 'it') {
|
|
104
|
+
env[methodName].todo = function (...args) {
|
|
105
|
+
return originalvitestFn.todo.apply(this, args);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
['beforeEach', 'afterEach', 'beforeAll', 'afterAll'].forEach((methodName) => {
|
|
110
|
+
const originalvitestFn = env[methodName];
|
|
111
|
+
env[methodName] = function (...args) {
|
|
112
|
+
args[0] = wrapTestInZone(args[0]);
|
|
113
|
+
return originalvitestFn.apply(this, args);
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
//# sourceMappingURL=setup-vitest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-vitest.js","sourceRoot":"","sources":["../../../packages/vite-plugin-angular/setup-vitest.ts"],"names":[],"mappings":";;AAAA,mBAAiB;AACjB,kCAAgC;AAChC,8BAA4B;AAC5B,2BAAyB;AAEzB;;;GAGG;AACH,iBAAiB;AACjB,MAAM,IAAI,GAAI,UAAkB,CAAC,MAAM,CAAC,CAAC;AAEzC,IAAI,IAAI,KAAK,SAAS,EAAE;IACtB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;CAC5C;AAED,IAAK,UAAkB,CAAC,uBAAuB,CAAC,KAAK,IAAI,EAAE;IACzD,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;CACnE;AAEA,UAAkB,CAAC,uBAAuB,CAAC,GAAG,IAAI,CAAC;AACpD,MAAM,gBAAgB,GAAG,IAAI,CAAC,kBAAkB,CAAC,CAAC;AAClD,MAAM,aAAa,GAAG,IAAI,CAAC,eAAe,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G,CAAC,UAAU,CAAC,CAAC;IACzC,GAAG,CAAC,UAAU,CAAC,GAAG,UAAU,GAAG,IAAW;QACxC,IAAI,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAElC,OAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5C,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as ts from 'typescript';
|
|
2
2
|
import { Plugin } from 'vite';
|
|
3
3
|
interface PluginOptions {
|
|
4
|
-
tsconfig
|
|
5
|
-
|
|
4
|
+
tsconfig?: string;
|
|
5
|
+
workspaceRoot?: string;
|
|
6
|
+
inlineStylesExtension?: string;
|
|
6
7
|
}
|
|
7
8
|
interface EmitFileResult {
|
|
8
9
|
content?: string;
|
|
@@ -11,6 +12,6 @@ interface EmitFileResult {
|
|
|
11
12
|
hash?: Uint8Array;
|
|
12
13
|
}
|
|
13
14
|
declare type FileEmitter = (file: string) => Promise<EmitFileResult | undefined>;
|
|
14
|
-
export declare function angular(
|
|
15
|
+
export declare function angular(options?: PluginOptions): Plugin[];
|
|
15
16
|
export declare function createFileEmitter(program: ts.BuilderProgram, transformers?: ts.CustomTransformers, onAfterEmit?: (sourceFile: ts.SourceFile) => void): FileEmitter;
|
|
16
17
|
export {};
|
|
@@ -9,15 +9,26 @@ const ts = require("typescript");
|
|
|
9
9
|
const compiler_plugin_1 = require("@angular-devkit/build-angular/src/builders/browser-esbuild/compiler-plugin");
|
|
10
10
|
const load_esm_1 = require("@angular-devkit/build-angular/src/utils/load-esm");
|
|
11
11
|
const component_resolvers_1 = require("./component-resolvers");
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const inline_styles_plugin_1 = require("./inline-styles-plugin");
|
|
13
|
+
function angular(options) {
|
|
14
|
+
var _a, _b, _c;
|
|
15
|
+
/**
|
|
16
|
+
* Normalize plugin options so defaults
|
|
17
|
+
* are used for values not provided.
|
|
18
|
+
*/
|
|
19
|
+
const pluginOptions = {
|
|
20
|
+
tsconfig: ((_a = options === null || options === void 0 ? void 0 : options.tsconfig) !== null && _a !== void 0 ? _a : process.env['NODE_ENV'] === 'test')
|
|
21
|
+
? './tsconfig.spec.json'
|
|
22
|
+
: './tsconfig.app.json',
|
|
23
|
+
workspaceRoot: (_b = options === null || options === void 0 ? void 0 : options.workspaceRoot) !== null && _b !== void 0 ? _b : process.cwd(),
|
|
24
|
+
inlineStylesExtension: (_c = options === null || options === void 0 ? void 0 : options.inlineStylesExtension) !== null && _c !== void 0 ? _c : '',
|
|
25
|
+
};
|
|
16
26
|
// The file emitter created during `onStart` that will be used during the build in `onLoad` callbacks for TS files
|
|
17
27
|
let fileEmitter;
|
|
18
28
|
let compilerOptions = {};
|
|
19
29
|
// Temporary deep import for transformer support
|
|
20
30
|
const { mergeTransformers, replaceBootstrap, } = require('@ngtools/webpack/src/ivy/transformation');
|
|
31
|
+
const { replaceResources, } = require('@ngtools/webpack/src/transformers/replace_resources');
|
|
21
32
|
const { augmentProgramWithVersioning, augmentHostWithCaching, } = require('@ngtools/webpack/src/ivy/host');
|
|
22
33
|
const { SourceFileCache } = require('@ngtools/webpack/src/ivy/cache');
|
|
23
34
|
let compilerCli;
|
|
@@ -27,7 +38,9 @@ function angular(pluginOptions = {
|
|
|
27
38
|
let builderProgram;
|
|
28
39
|
let watchMode = false;
|
|
29
40
|
let sourceFileCache = new SourceFileCache();
|
|
30
|
-
let isProd =
|
|
41
|
+
let isProd = process.env['NODE_ENV'] === 'production';
|
|
42
|
+
let isTest = process.env['NODE_ENV'] === 'test' || !!process.env['VITEST'];
|
|
43
|
+
let viteServer;
|
|
31
44
|
return [
|
|
32
45
|
{
|
|
33
46
|
name: '@analogjs/vite-plugin-angular',
|
|
@@ -36,6 +49,7 @@ function angular(pluginOptions = {
|
|
|
36
49
|
watchMode = command === 'serve';
|
|
37
50
|
compilerCli = yield (0, load_esm_1.loadEsmModule)('@angular/compiler-cli');
|
|
38
51
|
return {
|
|
52
|
+
assetsInclude: ['**/*.html'],
|
|
39
53
|
optimizeDeps: {
|
|
40
54
|
esbuildOptions: {
|
|
41
55
|
plugins: [
|
|
@@ -44,7 +58,8 @@ function angular(pluginOptions = {
|
|
|
44
58
|
sourcemap: !isProd,
|
|
45
59
|
advancedOptimizations: isProd,
|
|
46
60
|
}, {
|
|
47
|
-
|
|
61
|
+
workspaceRoot: pluginOptions.workspaceRoot,
|
|
62
|
+
sourcemap: !isProd,
|
|
48
63
|
optimization: isProd,
|
|
49
64
|
}),
|
|
50
65
|
],
|
|
@@ -58,34 +73,18 @@ function angular(pluginOptions = {
|
|
|
58
73
|
};
|
|
59
74
|
});
|
|
60
75
|
},
|
|
76
|
+
configureServer(server) {
|
|
77
|
+
viteServer = server;
|
|
78
|
+
server.watcher.on('add', setupCompilation);
|
|
79
|
+
server.watcher.on('unlink', setupCompilation);
|
|
80
|
+
},
|
|
61
81
|
buildStart() {
|
|
62
82
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
|
|
64
|
-
enableIvy: true,
|
|
65
|
-
noEmitOnError: false,
|
|
66
|
-
suppressOutputPathCheck: true,
|
|
67
|
-
outDir: undefined,
|
|
68
|
-
inlineSources: !isProd,
|
|
69
|
-
inlineSourceMap: !isProd,
|
|
70
|
-
sourceMap: false,
|
|
71
|
-
mapRoot: undefined,
|
|
72
|
-
sourceRoot: undefined,
|
|
73
|
-
declaration: false,
|
|
74
|
-
declarationMap: false,
|
|
75
|
-
allowEmptyCodegenFiles: false,
|
|
76
|
-
annotationsAs: 'decorators',
|
|
77
|
-
enableResourceInlining: false,
|
|
78
|
-
});
|
|
79
|
-
rootNames = rn;
|
|
80
|
-
compilerOptions = tsCompilerOptions;
|
|
81
|
-
host = ts.createIncrementalCompilerHost(compilerOptions);
|
|
82
|
-
// Setup source file caching and reuse cache from previous compilation if present
|
|
83
|
-
let cache = new SourceFileCache();
|
|
83
|
+
setupCompilation();
|
|
84
84
|
// Only store cache if in watch mode
|
|
85
85
|
if (watchMode) {
|
|
86
|
-
sourceFileCache
|
|
86
|
+
augmentHostWithCaching(host, sourceFileCache);
|
|
87
87
|
}
|
|
88
|
-
augmentHostWithCaching(host, cache);
|
|
89
88
|
yield buildAndAnalyze();
|
|
90
89
|
});
|
|
91
90
|
},
|
|
@@ -96,6 +95,14 @@ function angular(pluginOptions = {
|
|
|
96
95
|
yield buildAndAnalyze();
|
|
97
96
|
}
|
|
98
97
|
if (/\.(html|htm|css|less|sass|scss)$/.test(ctx.file)) {
|
|
98
|
+
/**
|
|
99
|
+
* Check to see if this was a direct request
|
|
100
|
+
* for an external resource (styles, html).
|
|
101
|
+
*/
|
|
102
|
+
const isDirect = ctx.modules.find((mod) => { var _a; return ctx.file === mod.file && ((_a = mod.id) === null || _a === void 0 ? void 0 : _a.includes('?direct')); });
|
|
103
|
+
if (isDirect) {
|
|
104
|
+
return ctx.modules;
|
|
105
|
+
}
|
|
99
106
|
let mods = [];
|
|
100
107
|
ctx.modules.forEach((mod) => {
|
|
101
108
|
mod.importers.forEach((imp) => {
|
|
@@ -118,24 +125,48 @@ function angular(pluginOptions = {
|
|
|
118
125
|
return;
|
|
119
126
|
}
|
|
120
127
|
if (/\.[cm]?tsx?$/.test(id)) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Re-analyze on each transform
|
|
130
|
+
* for test(Vitest)
|
|
131
|
+
*/
|
|
132
|
+
if (isTest) {
|
|
133
|
+
const tsMod = viteServer.moduleGraph.getModuleById(id);
|
|
134
|
+
if (tsMod) {
|
|
135
|
+
sourceFileCache.invalidate(id);
|
|
136
|
+
yield buildAndAnalyze();
|
|
125
137
|
}
|
|
126
138
|
}
|
|
127
|
-
if (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
139
|
+
if (watchMode) {
|
|
140
|
+
if ((0, component_resolvers_1.hasTemplateUrl)(code)) {
|
|
141
|
+
const templateUrl = (0, component_resolvers_1.resolveTemplateUrl)(code, id);
|
|
142
|
+
if (templateUrl) {
|
|
143
|
+
this.addWatchFile(templateUrl);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if ((0, component_resolvers_1.hasStyleUrls)(code)) {
|
|
147
|
+
const styleUrls = (0, component_resolvers_1.resolveStyleUrls)(code, id);
|
|
148
|
+
styleUrls.forEach((styleUrl) => {
|
|
149
|
+
this.addWatchFile(styleUrl);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
132
152
|
}
|
|
133
153
|
const typescriptResult = yield fileEmitter(id);
|
|
134
154
|
// return fileEmitter
|
|
135
155
|
const data = (_a = typescriptResult === null || typescriptResult === void 0 ? void 0 : typescriptResult.content) !== null && _a !== void 0 ? _a : '';
|
|
156
|
+
const forceAsyncTransformation = /for\s+await\s*\(|async\s+function\s*\*/.test(data);
|
|
157
|
+
const useInputSourcemap = (!isProd ? undefined : false);
|
|
158
|
+
if (!forceAsyncTransformation && !isProd) {
|
|
159
|
+
return {
|
|
160
|
+
code: isProd
|
|
161
|
+
? data.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, '')
|
|
162
|
+
: data,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
136
165
|
const babelResult = yield (0, core_1.transformAsync)(data, {
|
|
137
166
|
filename: id,
|
|
138
|
-
inputSourceMap: (
|
|
167
|
+
inputSourceMap: (useInputSourcemap
|
|
168
|
+
? undefined
|
|
169
|
+
: false),
|
|
139
170
|
sourceMaps: !isProd ? 'inline' : false,
|
|
140
171
|
compact: false,
|
|
141
172
|
configFile: false,
|
|
@@ -146,7 +177,7 @@ function angular(pluginOptions = {
|
|
|
146
177
|
[
|
|
147
178
|
application_1.default,
|
|
148
179
|
{
|
|
149
|
-
forceAsyncTransformation
|
|
180
|
+
forceAsyncTransformation,
|
|
150
181
|
optimize: isProd && {},
|
|
151
182
|
},
|
|
152
183
|
],
|
|
@@ -167,26 +198,27 @@ function angular(pluginOptions = {
|
|
|
167
198
|
config() {
|
|
168
199
|
return {
|
|
169
200
|
esbuild: {
|
|
170
|
-
minify: isProd,
|
|
171
|
-
minifyIdentifiers: true,
|
|
172
|
-
minifySyntax: true,
|
|
173
|
-
// NOTE: Disabling whitespace ensures unused pure annotations are kept
|
|
174
|
-
minifyWhitespace: false,
|
|
175
|
-
pure: ['forwardRef'],
|
|
176
201
|
legalComments: 'none',
|
|
177
|
-
// sourcefile: 'name',
|
|
178
|
-
sourcemap: !isProd,
|
|
179
|
-
define: {
|
|
180
|
-
ngDevMode: 'false',
|
|
181
|
-
ngJitMode: 'false',
|
|
182
|
-
ngI18nClosureMode: 'false',
|
|
183
|
-
},
|
|
184
|
-
// This option should always be disabled for browser builds as we don't rely on `.name`
|
|
185
|
-
// and causes deadcode to be retained which makes `NG_BUILD_MANGLE` unusable to investigate tree-shaking issues.
|
|
186
|
-
// We enable `keepNames` only for server builds as Domino relies on `.name`.
|
|
187
|
-
// Once we no longer rely on Domino for SSR we should be able to remove this.
|
|
188
202
|
keepNames: false,
|
|
189
|
-
|
|
203
|
+
define: isProd
|
|
204
|
+
? {
|
|
205
|
+
ngDevMode: 'false',
|
|
206
|
+
ngJitMode: 'false',
|
|
207
|
+
ngI18nClosureMode: 'false',
|
|
208
|
+
}
|
|
209
|
+
: undefined,
|
|
210
|
+
supported: {
|
|
211
|
+
// Native async/await is not supported with Zone.js. Disabling support here will cause
|
|
212
|
+
// esbuild to downlevel async/await to a Zone.js supported form.
|
|
213
|
+
'async-await': false,
|
|
214
|
+
// Zone.js also does not support async generators or async iterators. However, esbuild does
|
|
215
|
+
// not currently support downleveling either of them. Instead babel is used within the JS/TS
|
|
216
|
+
// loader to perform the downlevel transformation. They are both disabled here to allow
|
|
217
|
+
// esbuild to handle them in the future if support is ever added.
|
|
218
|
+
// NOTE: If esbuild adds support in the future, the babel support for these can be disabled.
|
|
219
|
+
'async-generator': false,
|
|
220
|
+
'for-await': false,
|
|
221
|
+
},
|
|
190
222
|
},
|
|
191
223
|
};
|
|
192
224
|
},
|
|
@@ -195,12 +227,20 @@ function angular(pluginOptions = {
|
|
|
195
227
|
if (/\.[cm]?js$/.test(id)) {
|
|
196
228
|
const angularPackage = /[\\/]node_modules[\\/]@angular[\\/]/.test(id);
|
|
197
229
|
const linkerPluginCreator = (yield (0, load_esm_1.loadEsmModule)('@angular/compiler-cli/linker/babel')).createEs2015LinkerPlugin;
|
|
198
|
-
const
|
|
230
|
+
const forceAsyncTransformation = !/[\\/][_f]?esm2015[\\/]/.test(id) &&
|
|
231
|
+
/for\s+await\s*\(|async\s+function\s*\*/.test(code);
|
|
232
|
+
const shouldLink = yield (0, webpack_loader_1.requiresLinking)(id, code);
|
|
233
|
+
const useInputSourcemap = (!isProd ? undefined : false);
|
|
234
|
+
if (!forceAsyncTransformation && !isProd && !shouldLink) {
|
|
235
|
+
return {
|
|
236
|
+
code: isProd
|
|
237
|
+
? code.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, '')
|
|
238
|
+
: code,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
199
241
|
const result = yield (0, core_1.transformAsync)(code, {
|
|
200
242
|
filename: id,
|
|
201
|
-
inputSourceMap:
|
|
202
|
-
? undefined
|
|
203
|
-
: false),
|
|
243
|
+
inputSourceMap: useInputSourcemap,
|
|
204
244
|
sourceMaps: !isProd ? 'inline' : false,
|
|
205
245
|
compact: false,
|
|
206
246
|
configFile: false,
|
|
@@ -212,12 +252,11 @@ function angular(pluginOptions = {
|
|
|
212
252
|
application_1.default,
|
|
213
253
|
{
|
|
214
254
|
angularLinker: {
|
|
215
|
-
shouldLink
|
|
255
|
+
shouldLink,
|
|
216
256
|
jitMode: false,
|
|
217
257
|
linkerPluginCreator,
|
|
218
258
|
},
|
|
219
|
-
forceAsyncTransformation
|
|
220
|
-
code.includes('async'),
|
|
259
|
+
forceAsyncTransformation,
|
|
221
260
|
optimize: isProd && {
|
|
222
261
|
looseEnums: angularPackage,
|
|
223
262
|
pureTopLevel: angularPackage,
|
|
@@ -235,7 +274,29 @@ function angular(pluginOptions = {
|
|
|
235
274
|
});
|
|
236
275
|
},
|
|
237
276
|
},
|
|
277
|
+
(0, inline_styles_plugin_1.inlineStylesPlugin)(pluginOptions.inlineStylesExtension),
|
|
238
278
|
];
|
|
279
|
+
function setupCompilation() {
|
|
280
|
+
const { options: tsCompilerOptions, rootNames: rn } = compilerCli.readConfiguration(pluginOptions.tsconfig, {
|
|
281
|
+
enableIvy: true,
|
|
282
|
+
noEmitOnError: false,
|
|
283
|
+
suppressOutputPathCheck: true,
|
|
284
|
+
outDir: undefined,
|
|
285
|
+
inlineSources: !isProd,
|
|
286
|
+
inlineSourceMap: !isProd,
|
|
287
|
+
sourceMap: false,
|
|
288
|
+
mapRoot: undefined,
|
|
289
|
+
sourceRoot: undefined,
|
|
290
|
+
declaration: false,
|
|
291
|
+
declarationMap: false,
|
|
292
|
+
allowEmptyCodegenFiles: false,
|
|
293
|
+
annotationsAs: 'decorators',
|
|
294
|
+
enableResourceInlining: false,
|
|
295
|
+
});
|
|
296
|
+
rootNames = rn;
|
|
297
|
+
compilerOptions = tsCompilerOptions;
|
|
298
|
+
host = ts.createIncrementalCompilerHost(compilerOptions);
|
|
299
|
+
}
|
|
239
300
|
/**
|
|
240
301
|
* Creates a new NgtscProgram to analyze/re-analyze
|
|
241
302
|
* the source files and create a file emitter.
|
|
@@ -260,9 +321,13 @@ function angular(pluginOptions = {
|
|
|
260
321
|
builder = ts.createAbstractBuilder(typeScriptProgram, host);
|
|
261
322
|
}
|
|
262
323
|
yield angularCompiler.analyzeAsync();
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
324
|
+
const getTypeChecker = () => builder.getProgram().getTypeChecker();
|
|
325
|
+
fileEmitter = createFileEmitter(builder, mergeTransformers({
|
|
326
|
+
before: [
|
|
327
|
+
replaceBootstrap(getTypeChecker),
|
|
328
|
+
replaceResources(() => true, getTypeChecker, pluginOptions.inlineStylesExtension),
|
|
329
|
+
],
|
|
330
|
+
}, angularCompiler.prepareEmit().transformers), () => []);
|
|
266
331
|
});
|
|
267
332
|
}
|
|
268
333
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"angular-vite-plugin.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts"],"names":[],"mappings":";;;;AACA,sCAA6C;AAC7C,6FAAmG;AACnG,2FAAyF;
|
|
1
|
+
{"version":3,"file":"angular-vite-plugin.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts"],"names":[],"mappings":";;;;AACA,sCAA6C;AAC7C,6FAAmG;AACnG,2FAAyF;AACzF,iCAAiC;AAGjC,gHAAkH;AAClH,+EAAiF;AACjF,+DAK+B;AAC/B,iEAA4D;AAgB5D,SAAgB,OAAO,CAAC,OAAuB;;IAC7C;;;OAGG;IACH,MAAM,aAAa,GAAG;QACpB,QAAQ,EACN,CAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,mCAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,MAAM;YACrD,CAAC,CAAC,sBAAsB;YACxB,CAAC,CAAC,qBAAqB;QAC3B,aAAa,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,mCAAI,OAAO,CAAC,GAAG,EAAE;QACtD,qBAAqB,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,qBAAqB,mCAAI,EAAE;KAC5D,CAAC;IAEF,kHAAkH;IAClH,IAAI,WAAoC,CAAC;IACzC,IAAI,eAAe,GAAG,EAAE,CAAC;IACzB,gDAAgD;IAChD,MAAM,EACJ,iBAAiB,EACjB,gBAAgB,GACjB,GAAG,OAAO,CAAC,yCAAyC,CAAC,CAAC;IACvD,MAAM,EACJ,gBAAgB,GACjB,GA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1,10 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* This plugin decodes and returns inline styles that were
|
|
4
|
+
* extracted from the Component decorator metadata and encoded
|
|
5
|
+
* into the import string. This allows Vite to intercept
|
|
6
|
+
* these imports, convert them into virtual modules, and
|
|
7
|
+
* return them as imported styles to pass through the CSS
|
|
8
|
+
* transform pipeline.
|
|
9
|
+
*/
|
|
10
|
+
export declare function inlineStylesPlugin(inlineStylesExtension?: string): Plugin;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inlineStylesPlugin = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const virtualModuleId = 'virtual:analog-inline-styles-module';
|
|
6
|
+
/**
|
|
7
|
+
* This plugin decodes and returns inline styles that were
|
|
8
|
+
* extracted from the Component decorator metadata and encoded
|
|
9
|
+
* into the import string. This allows Vite to intercept
|
|
10
|
+
* these imports, convert them into virtual modules, and
|
|
11
|
+
* return them as imported styles to pass through the CSS
|
|
12
|
+
* transform pipeline.
|
|
13
|
+
*/
|
|
14
|
+
function inlineStylesPlugin(inlineStylesExtension = '') {
|
|
15
|
+
return {
|
|
16
|
+
name: '@analogjs/vite-plugin-angular-inline-styles',
|
|
17
|
+
enforce: 'pre',
|
|
18
|
+
resolveId(id) {
|
|
19
|
+
if (id.includes(`.${inlineStylesExtension}?ngResource`) &&
|
|
20
|
+
/data=(.*)\!/.test(id)) {
|
|
21
|
+
return '\0' + virtualModuleId + id;
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
},
|
|
25
|
+
load(id) {
|
|
26
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
if (!id.startsWith(`\0${virtualModuleId}`)) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const encodedStyles = id.match(/data=(.*)\!/)[1];
|
|
31
|
+
const styles = Buffer.from(decodeURIComponent(encodedStyles), 'base64').toString();
|
|
32
|
+
return {
|
|
33
|
+
code: styles,
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
exports.inlineStylesPlugin = inlineStylesPlugin;
|
|
40
|
+
//# sourceMappingURL=inline-styles-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-styles-plugin.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-angular/src/lib/inline-styles-plugin.ts"],"names":[],"mappings":";;;;AAEA,MAAM,eAAe,GAAG,qCAAqC,CAAC;AAE9D;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAAC,qBAAqB,GAAG,EAAE;IAC3D,OAAO;QACL,IAAI,EAAE,6CAA6C;QACnD,OAAO,EAAE,KAAK;QACd,SAAS,CAAC,EAAE;YACV,IACE,EAAE,CAAC,QAAQ,CAAC,IAAI,qBAAqB,aAAa,CAAC;gBACnD,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,EACtB;gBACA,OAAO,IAAI,GAAG,eAAe,GAAG,EAAE,CAAC;aACpC;YAED,OAAO,SAAS,CAAC;QACnB,CAAC;QACK,IAAI,CAAC,EAAE;;gBACX,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,eAAe,EAAE,CAAC,EAAE;oBAC1C,OAAO,SAAS,CAAC;iBAClB;gBAED,MAAM,aAAa,GAAG,EAAE,CAAC,KAAK,CAAC,aAAa,CAAE,CAAC,CAAC,CAAC,CAAC;gBAClD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CACxB,kBAAkB,CAAC,aAAa,CAAC,EACjC,QAAQ,CACT,CAAC,QAAQ,EAAE,CAAC;gBAEb,OAAO;oBACL,IAAI,EAAE,MAAM;iBACb,CAAC;YACJ,CAAC;SAAA;KACF,CAAC;AACJ,CAAC;AA9BD,gDA8BC"}
|