Skip to content

Commit

Permalink
feat(cli): update flag defaults for V3 (#3502)
Browse files Browse the repository at this point in the history
update the following configuration defaults:
- the root-level `sourceMaps` flag now defaults to `true`.
- `dist-custom-elements` config `generateTypeDeclarations` flag now defaults to `true` 

STENCIL-396: Implement New Sensible Defaults for V3

BREAKING CHANGE: sourcemaps are enabled by default for all output targets, and type declarations are automatically created for the `dist-custom-elements` output target
  • Loading branch information
tanner-reits authored and rwaskiewicz committed Jan 25, 2023
1 parent 3b480c6 commit c78dd20
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 6 deletions.
1 change: 1 addition & 0 deletions BREAKING_CHANGES.md
Expand Up @@ -652,6 +652,7 @@ Stencil v3.0.0 is in development at this time and has not been released. The lis
change. Further details on each of these items will be included prior to the release.

- [fix(testing): puppeteer v10 support #2934](https://github.com/ionic-team/stencil/pull/2934)
- [feat(cli): update flag defaults for V3 #3502](https://github.com/ionic-team/stencil/pull/3502)

## DEPRECATIONS

Expand Down
3 changes: 3 additions & 0 deletions src/compiler/config/outputs/validate-custom-element.ts
Expand Up @@ -37,6 +37,9 @@ export const validateCustomElement = (
if (!isBoolean(outputTarget.externalRuntime)) {
outputTarget.externalRuntime = true;
}
if (!isBoolean(outputTarget.generateTypeDeclarations)) {
outputTarget.generateTypeDeclarations = true;
}

// unlike other output targets, Stencil does not allow users to define the output location of types at this time
if (outputTarget.generateTypeDeclarations) {
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/config/test/validate-config-sourcemap.spec.ts
Expand Up @@ -54,13 +54,13 @@ describe('stencil config - sourceMap option', () => {
expect(inlineSources).toBe(false);
});

it('sets the sourceMap options to false in tsconfig by default', async () => {
it('sets the sourceMap options to true in tsconfig by default', async () => {
const testConfig = getLoadConfigForTests();

const loadConfigResults = await loadConfig(testConfig);

const { sourceMap, inlineSources } = loadConfigResults.config.tsCompilerOptions;
expect(sourceMap).toBe(false);
expect(inlineSources).toBe(false);
expect(sourceMap).toBe(true);
expect(inlineSources).toBe(true);
});
});
4 changes: 2 additions & 2 deletions src/compiler/config/test/validate-config.spec.ts
Expand Up @@ -430,9 +430,9 @@ describe('validation', () => {
expect(config.sourceMap).toBe(false);
});

it('defaults the field to false when not set in the config', () => {
it('defaults the field to true when not set in the config', () => {
const { config } = validateConfig(userConfig, bootstrapConfig);
expect(config.sourceMap).toBe(false);
expect(config.sourceMap).toBe(true);
});
});

Expand Down
Expand Up @@ -24,12 +24,18 @@ describe('validate-output-dist-custom-element', () => {

const { config } = validateConfig(userConfig, mockLoadConfigInit());
expect(config.outputTargets).toEqual([
{
type: DIST_TYPES,
dir: defaultDistDir,
typesDir: path.join(rootDir, 'dist', 'types'),
},
{
type: DIST_CUSTOM_ELEMENTS,
copy: [],
dir: defaultDistDir,
empty: true,
externalRuntime: true,
generateTypeDeclarations: true,
},
]);
});
Expand All @@ -38,6 +44,7 @@ describe('validate-output-dist-custom-element', () => {
const outputTarget: d.OutputTargetDistCustomElements = {
type: DIST_CUSTOM_ELEMENTS,
dir: distCustomElementsDir,
generateTypeDeclarations: false,
};
userConfig.outputTargets = [outputTarget];

Expand All @@ -49,6 +56,7 @@ describe('validate-output-dist-custom-element', () => {
dir: path.join(rootDir, distCustomElementsDir),
empty: true,
externalRuntime: true,
generateTypeDeclarations: false,
},
]);
});
Expand All @@ -58,6 +66,7 @@ describe('validate-output-dist-custom-element', () => {
const outputTarget: d.OutputTargetDistCustomElements = {
type: DIST_CUSTOM_ELEMENTS,
externalRuntime: false,
generateTypeDeclarations: false,
};
userConfig.outputTargets = [outputTarget];

Expand All @@ -69,6 +78,7 @@ describe('validate-output-dist-custom-element', () => {
dir: defaultDistDir,
empty: true,
externalRuntime: false,
generateTypeDeclarations: false,
},
]);
});
Expand All @@ -78,6 +88,7 @@ describe('validate-output-dist-custom-element', () => {
type: DIST_CUSTOM_ELEMENTS,
empty: undefined,
externalRuntime: false,
generateTypeDeclarations: false,
};
userConfig.outputTargets = [outputTarget];

Expand All @@ -89,6 +100,7 @@ describe('validate-output-dist-custom-element', () => {
dir: defaultDistDir,
empty: true,
externalRuntime: false,
generateTypeDeclarations: false,
},
]);
});
Expand All @@ -99,6 +111,7 @@ describe('validate-output-dist-custom-element', () => {
const outputTarget: d.OutputTargetDistCustomElements = {
type: DIST_CUSTOM_ELEMENTS,
empty: false,
generateTypeDeclarations: false,
};
userConfig.outputTargets = [outputTarget];

Expand All @@ -110,6 +123,7 @@ describe('validate-output-dist-custom-element', () => {
dir: defaultDistDir,
empty: false,
externalRuntime: true,
generateTypeDeclarations: false,
},
]);
});
Expand All @@ -119,6 +133,7 @@ describe('validate-output-dist-custom-element', () => {
type: DIST_CUSTOM_ELEMENTS,
empty: false,
externalRuntime: undefined,
generateTypeDeclarations: false,
};
userConfig.outputTargets = [outputTarget];

Expand All @@ -130,12 +145,64 @@ describe('validate-output-dist-custom-element', () => {
dir: defaultDistDir,
empty: false,
externalRuntime: true,
generateTypeDeclarations: false,
},
]);
});
});

describe('"generateTypeDeclarations" field', () => {
it('defaults the "generateTypeDeclarations" field to true if not provided', () => {
const outputTarget: d.OutputTargetDistCustomElements = {
type: DIST_CUSTOM_ELEMENTS,
empty: false,
};
userConfig.outputTargets = [outputTarget];

const { config } = validateConfig(userConfig, mockLoadConfigInit());
expect(config.outputTargets).toEqual([
{
type: DIST_TYPES,
dir: defaultDistDir,
typesDir: path.join(rootDir, 'dist', 'types'),
},
{
type: DIST_CUSTOM_ELEMENTS,
copy: [],
dir: defaultDistDir,
empty: false,
externalRuntime: true,
generateTypeDeclarations: true,
},
]);
});

it('defaults the "generateTypeDeclarations" field to true it\'s not a boolean', () => {
const outputTarget: d.OutputTargetDistCustomElements = {
type: DIST_CUSTOM_ELEMENTS,
empty: false,
generateTypeDeclarations: undefined,
};
userConfig.outputTargets = [outputTarget];

const { config } = validateConfig(userConfig, mockLoadConfigInit());
expect(config.outputTargets).toEqual([
{
type: DIST_TYPES,
dir: defaultDistDir,
typesDir: path.join(rootDir, 'dist', 'types'),
},
{
type: DIST_CUSTOM_ELEMENTS,
copy: [],
dir: defaultDistDir,
empty: false,
externalRuntime: true,
generateTypeDeclarations: true,
},
]);
});

it('creates a types directory when "generateTypeDeclarations" is true', () => {
const outputTarget: d.OutputTargetDistCustomElements = {
type: DIST_CUSTOM_ELEMENTS,
Expand Down Expand Up @@ -231,6 +298,7 @@ describe('validate-output-dist-custom-element', () => {
dir: distCustomElementsDir,
empty: false,
externalRuntime: false,
generateTypeDeclarations: false,
};
userConfig.outputTargets = [outputTarget];

Expand All @@ -247,6 +315,7 @@ describe('validate-output-dist-custom-element', () => {
dir: path.join(rootDir, distCustomElementsDir),
empty: false,
externalRuntime: false,
generateTypeDeclarations: false,
},
]);
});
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/config/validate-config.ts
Expand Up @@ -90,7 +90,7 @@ export const validateConfig = (
validatedConfig,
'sourceMap',
null,
typeof validatedConfig.sourceMap === 'undefined' ? false : validatedConfig.sourceMap
typeof validatedConfig.sourceMap === 'undefined' ? true : validatedConfig.sourceMap
);
setBooleanConfig(validatedConfig, 'watch', 'watch', false);
setBooleanConfig(validatedConfig, 'buildDocs', 'docs', !validatedConfig.devMode);
Expand Down

0 comments on commit c78dd20

Please sign in to comment.