Skip to content

Commit b10e93b

Browse files
authored
Merge branch 'main' into feat/add-type-parameters-to-class-name
2 parents 008d1dd + a6a9171 commit b10e93b

File tree

8 files changed

+57
-110
lines changed

8 files changed

+57
-110
lines changed

src/cli/run.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,27 @@ export const run = async (init: d.CliInitOptions) => {
113113
}
114114
};
115115

116+
/**
117+
* Run a specified task
118+
* @param coreCompiler an instance of a minimal, bootstrap compiler for running the specified task
119+
* @param config a configuration for the Stencil project to apply to the task run
120+
* @param task the task to run
121+
* @param sys the {@link CompilerSystem} for interacting with the operating system
122+
* @public
123+
*/
116124
export const runTask = async (
117125
coreCompiler: CoreCompiler,
118126
config: d.Config,
119127
task: d.TaskCommand,
120128
sys?: d.CompilerSystem
121-
) => {
129+
): Promise<void> => {
122130
const logger = config.logger ?? createLogger();
123131
const strictConfig: ValidatedConfig = {
124132
...config,
125133
flags: createConfigFlags(config.flags ?? { task }),
126134
logger,
127135
outputTargets: config.outputTargets ?? [],
136+
sys: sys ?? coreCompiler.createSystem({ logger }),
128137
};
129138

130139
switch (task) {

src/cli/telemetry/test/telemetry.spec.ts

Lines changed: 34 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type * as d from '../../../declarations';
22
import * as telemetry from '../telemetry';
33
import * as shouldTrack from '../shouldTrack';
44
import { createSystem } from '../../../compiler/sys/stencil-sys';
5-
import { mockLogger, mockValidatedConfig } from '@stencil/core/testing';
5+
import { mockValidatedConfig } from '@stencil/core/testing';
66
import * as coreCompiler from '@stencil/core/compiler';
77
import { anonymizeConfigForTelemetry } from '../telemetry';
88
import { DIST, DIST_CUSTOM_ELEMENTS, DIST_HYDRATE_SCRIPT, WWW } from '../../../compiler/output-targets/output-utils';
@@ -148,25 +148,21 @@ describe('prepareData', () => {
148148
let sys: d.CompilerSystem;
149149

150150
beforeEach(() => {
151-
config = {
152-
outputTargets: [],
153-
flags: createConfigFlags(),
154-
logger: mockLogger(),
155-
};
156-
157-
sys = createSystem();
151+
config = mockValidatedConfig();
152+
sys = config.sys;
153+
// set static name + versions, otherwise tests will pull in the dev build's data (which changes per build)
154+
sys.name = 'in-memory';
155+
sys.version = '__VERSION:STENCIL__';
158156
});
159157

160-
it('provides an object', async () => {
158+
it('prepares an object to send to ionic', async () => {
161159
const data = await telemetry.prepareData(coreCompiler, config, sys, 1000);
162160
expect(data).toEqual({
163161
arguments: [],
164162
build: coreCompiler.buildId,
165163
component_count: undefined,
166-
config: {
167-
flags: createConfigFlags(),
168-
outputTargets: [],
169-
},
164+
// the configuration generation is tested elsewhere, just verify we're sending something under this flag
165+
config: expect.any(Object),
170166
cpu_model: '',
171167
duration_ms: 1000,
172168
has_app_pwa_config: false,
@@ -185,101 +181,39 @@ describe('prepareData', () => {
185181
});
186182
});
187183

188-
it('updates when there is a PWA config', async () => {
189-
const config: d.ValidatedConfig = {
190-
flags: createConfigFlags(),
191-
logger: mockLogger(),
192-
outputTargets: [{ type: 'www', baseUrl: 'https://example.com', serviceWorker: { swDest: './tmp' } }],
193-
};
184+
describe('has_app_pwa_config property', () => {
185+
it('sets `has_app_pwa_config` to true when there is a service worker', async () => {
186+
const config = mockValidatedConfig({
187+
outputTargets: [{ type: 'www', baseUrl: 'https://example.com' }],
188+
});
194189

195-
const data = await telemetry.prepareData(coreCompiler, config, sys, 1000);
190+
const data = await telemetry.prepareData(coreCompiler, config, sys, 1000);
196191

197-
expect(data).toEqual({
198-
arguments: [],
199-
build: coreCompiler.buildId,
200-
component_count: undefined,
201-
config: {
202-
flags: {
203-
args: [],
204-
knownArgs: [],
205-
task: null,
206-
unknownArgs: [],
207-
},
208-
outputTargets: [
209-
{
210-
baseUrl: 'omitted',
211-
serviceWorker: {
212-
swDest: 'omitted',
213-
},
214-
type: 'www',
215-
},
216-
],
217-
},
218-
cpu_model: '',
219-
duration_ms: 1000,
220-
has_app_pwa_config: true,
221-
os_name: '',
222-
os_version: '',
223-
packages: [],
224-
packages_no_versions: [],
225-
rollup: coreCompiler.versions.rollup,
226-
stencil: coreCompiler.versions.stencil,
227-
system: 'in-memory __VERSION:STENCIL__',
228-
system_major: 'in-memory __VERSION:STENCIL__',
229-
targets: ['www'],
230-
task: null,
231-
typescript: coreCompiler.versions.typescript,
232-
yarn: false,
192+
expect(data.has_app_pwa_config).toBe(true);
233193
});
234-
});
235194

236-
it('updates when there is a component count passed in', async () => {
237-
const config: d.ValidatedConfig = {
238-
flags: createConfigFlags(),
239-
logger: mockLogger(),
240-
outputTargets: [{ type: 'www', baseUrl: 'https://example.com', serviceWorker: { swDest: './tmp' } }],
241-
};
195+
it("sets `has_app_pwa_config` to true for a non '/' baseUrl", async () => {
196+
const config = mockValidatedConfig({
197+
outputTargets: [{ type: 'www', serviceWorker: { swDest: './tmp' } }],
198+
});
242199

243-
const data = await telemetry.prepareData(coreCompiler, config, sys, 1000, 12);
200+
const data = await telemetry.prepareData(coreCompiler, config, sys, 1000);
244201

245-
expect(data).toEqual({
246-
arguments: [],
247-
build: coreCompiler.buildId,
248-
component_count: 12,
249-
config: {
250-
flags: {
251-
args: [],
252-
knownArgs: [],
253-
task: null,
254-
unknownArgs: [],
255-
},
256-
outputTargets: [
257-
{
258-
baseUrl: 'omitted',
259-
serviceWorker: {
260-
swDest: 'omitted',
261-
},
262-
type: WWW,
263-
},
264-
],
265-
},
266-
cpu_model: '',
267-
duration_ms: 1000,
268-
has_app_pwa_config: true,
269-
os_name: '',
270-
os_version: '',
271-
packages: [],
272-
packages_no_versions: [],
273-
rollup: coreCompiler.versions.rollup,
274-
stencil: coreCompiler.versions.stencil,
275-
system: 'in-memory __VERSION:STENCIL__',
276-
system_major: 'in-memory __VERSION:STENCIL__',
277-
targets: ['www'],
278-
task: null,
279-
typescript: coreCompiler.versions.typescript,
280-
yarn: false,
202+
expect(data.has_app_pwa_config).toBe(true);
281203
});
282204
});
205+
206+
it('sends a component count when one is provided', async () => {
207+
const COMPONENT_COUNT = 12;
208+
209+
const config = mockValidatedConfig({
210+
outputTargets: [{ type: 'www' }],
211+
});
212+
213+
const data = await telemetry.prepareData(coreCompiler, config, sys, 1000, COMPONENT_COUNT);
214+
215+
expect(data.component_count).toEqual(COMPONENT_COUNT);
216+
});
283217
});
284218

285219
describe('anonymizeConfigForTelemetry', () => {

src/compiler/compiler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Compiler, Config, Diagnostic } from '../declarations';
1+
import type { Compiler, Config, Diagnostic, ValidatedConfig } from '../declarations';
22
import { Cache } from './cache';
33
import { CompilerContext } from './build/compiler-ctx';
44
import { createFullBuild } from './build/full-build';
@@ -22,7 +22,7 @@ export const createCompiler = async (userConfig: Config): Promise<Compiler> => {
2222
// actual compiler code
2323
// could be in a web worker on the browser
2424
// or the main thread in node
25-
const config = getConfig(userConfig);
25+
const config: ValidatedConfig = getConfig(userConfig);
2626
const diagnostics: Diagnostic[] = [];
2727
const sys = config.sys;
2828
const compilerCtx = new CompilerContext();

src/compiler/config/load-config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ export const loadConfig = async (init: LoadConfigInit = {}): Promise<LoadConfigR
4646
const unknownConfig: UnvalidatedConfig = {};
4747

4848
try {
49-
const sys = init.sys || createSystem();
5049
const config = init.config || {};
5150
let configPath = init.configPath || config.configPath;
5251

52+
// Pull the {@link CompilerSystem} out of the initialization object, or create one if it does not exist.
53+
// This entity is needed to load the project's configuration (and therefore needs to be created before it can be
54+
// attached to a configuration entity, validated or otherwise)
55+
const sys = init.sys ?? createSystem();
56+
5357
const loadedConfigFile = await loadConfigFile(sys, results.diagnostics, configPath);
5458
if (hasError(results.diagnostics)) {
5559
return results;

src/compiler/config/validate-config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { validateRollupConfig } from './validate-rollup-config';
1212
import { validateTesting } from './validate-testing';
1313
import { validateWorkers } from './validate-workers';
1414
import { createLogger } from '../sys/logger/console-logger';
15+
import { createSystem } from '../sys/stencil-sys';
1516

1617
/**
1718
* Represents the results of validating a previously unvalidated configuration
@@ -41,7 +42,7 @@ export const validateConfig = (
4142
userConfig: UnvalidatedConfig = {},
4243
bootstrapConfig: LoadConfigInit
4344
): ConfigValidationResults => {
44-
const config = Object.assign({}, userConfig || {}); // not positive it's json safe
45+
const config = Object.assign({}, userConfig); // not positive it's json safe
4546
const diagnostics: Diagnostic[] = [];
4647

4748
const logger = bootstrapConfig.logger || config.logger || createLogger();
@@ -52,6 +53,7 @@ export const validateConfig = (
5253
flags: JSON.parse(JSON.stringify(config.flags || {})),
5354
logger,
5455
outputTargets: config.outputTargets ?? [],
56+
sys: config.sys ?? bootstrapConfig.sys ?? createSystem({ logger }),
5557
};
5658

5759
// default devMode false

src/compiler/sys/config.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ export const getConfig = (userConfig: d.Config): d.ValidatedConfig => {
1111
flags: createConfigFlags(userConfig.flags ?? {}),
1212
logger,
1313
outputTargets: userConfig.outputTargets ?? [],
14+
sys: userConfig.sys ?? createSystem({ logger }),
1415
};
1516

16-
if (!config.sys) {
17-
config.sys = createSystem({ logger: config.logger });
18-
}
19-
2017
setPlatformPath(config.sys.platformPath);
2118

2219
if (config.flags.debug || config.flags.verbose) {

src/declarations/stencil-public-compiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ type RequireFields<T, K extends keyof T> = T & { [P in K]-?: T[P] };
409409
/**
410410
* Fields in {@link Config} to make required for {@link ValidatedConfig}
411411
*/
412-
type StrictConfigFields = 'flags' | 'logger' | 'outputTargets';
412+
type StrictConfigFields = 'flags' | 'logger' | 'outputTargets' | 'sys';
413413

414414
/**
415415
* A version of {@link Config} that makes certain fields required. This type represents a valid configuration entity.

src/testing/mocks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export function mockValidatedConfig(overrides: Partial<ValidatedConfig> = {}): V
3535
flags: createConfigFlags(),
3636
logger: mockLogger(),
3737
outputTargets: baseConfig.outputTargets ?? [],
38+
sys: createTestingSystem(),
3839
...overrides,
3940
};
4041
}

0 commit comments

Comments
 (0)