Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions scripts/bundles/internal-platform-hydrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@ export async function internalHydrate(opts: BuildOptions) {
banner: getBanner(opts, 'Stencil Hydrate Platform'),
preferConst: true,
},
/**
* The `internal-platform-hydrate` bundle depends on functions which use
* the output-target utils which, in turn, imports `path`. However, none of
* the functions which it uses actually _use_ functioned exported by `path`,
* so when bundling it doesn't actually import anything from `path` but if
* you don't set this option Rollup will leave an unqualified import like
* so:
*
* ```ts
* import "path";
* ```
*
* If you say `moduleSideEffects: false` you're basically saying 'dont assume
* that imported a module has a desired side effect' which allows an import that
* doesn't result in any symbols being pulled into the importing module to be
* eliminated.
*
* Another way to say this is that without this change the treeshaking
* validation for `test.dist` doesn't pass for this bundle.
*/
treeshake: {
moduleSideEffects: false,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the internal-platform-hydrate bundle depends on functions which use the output-target utils which, in turn, imports path. However, none of the functions which it uses actually use functioned exported by path, so when bundling it doesn't actually import anything from path but if you don't set this option Rollup will leave an unqualified import like so:

import "path";

if you say moduleSideEffects: false you're basically saying 'dont assume that imported a module has a desired side effect' which allows an import that doesn't result in any symbols being pulled into the importing module to be eliminated.

Another way to say this is that without this change the treeshaking validation for test.dist doesn't pass for this bundle.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we capture this info in a comment for future us?

plugins: [
{
name: 'internalHydratePlugin',
Expand Down Expand Up @@ -66,6 +89,17 @@ export async function internalHydrate(opts: BuildOptions) {
banner: getBanner(opts, 'Stencil Hydrate Runner'),
preferConst: true,
},
/**
* See above for an explanation, this is necessary to eliminate an
* unqualified import of `"path"`, like so:
*
* ```ts
* import "path";
* ```
*/
treeshake: {
moduleSideEffects: false,
},
plugins: [
aliasPlugin(opts),
replacePlugin(opts),
Expand Down
3 changes: 2 additions & 1 deletion src/cli/task-docs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isOutputTargetDocs } from '../compiler/output-targets/output-utils';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when I was fiddling with build stuff I noticed this relative import from src/compiler/ which was causing code from within the compiler bundle be also pulled into the cli bundle. I considered a bit how to address it - we could export the output targets related utils (and constants) from the compiler bundle, making this into something like

import { isOutputTargetDocs } from '@stencil/core'

but I thought that wasn't too great for a few reasons, mainly that it changes the public API of @stencil/core. I also thought just for organization, if the output target related utils are used across the codebase they should really live in the src/utils directory and therefore be importable from the @utils namespace. So I thought we should look at moving the functions to src/utils/output-target.ts and moving the constants to src/utils/constants.ts

import { isOutputTargetDocs } from '@utils';

import type { ValidatedConfig } from '../declarations';
import type { CoreCompiler } from './load-compiler';
import { startupCompilerLog } from './logs';
Expand Down
3 changes: 2 additions & 1 deletion src/cli/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isOutputTargetHydrate, WWW } from '../../compiler/output-targets/output-utils';
import { isOutputTargetHydrate, WWW } from '@utils';

import { IS_BROWSER_ENV } from '../../compiler/sys/environment';
import type * as d from '../../declarations';
import { readConfig, updateConfig, writeConfig } from '../ionic-config';
Expand Down
2 changes: 1 addition & 1 deletion src/cli/telemetry/test/telemetry.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as coreCompiler from '@stencil/core/compiler';
import { mockValidatedConfig } from '@stencil/core/testing';
import { DIST, DIST_CUSTOM_ELEMENTS, DIST_HYDRATE_SCRIPT, WWW } from '@utils';

import { createConfigFlags } from '../../../cli/config-flags';
import { DIST, DIST_CUSTOM_ELEMENTS, DIST_HYDRATE_SCRIPT, WWW } from '../../../compiler/output-targets/output-utils';
import * as environment from '../../../compiler/sys/environment';
import { createSystem } from '../../../compiler/sys/stencil-sys';
import type * as d from '../../../declarations';
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/build/build-hmr.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { isGlob, normalizePath, sortBy } from '@utils';
import { isGlob, isOutputTargetWww, normalizePath, sortBy } from '@utils';
import minimatch from 'minimatch';
import { basename } from 'path';

import type * as d from '../../declarations';
import { isOutputTargetWww } from '../output-targets/output-utils';
import { getScopeId } from '../style/scope-css';

export const generateHmr = (config: d.Config, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx) => {
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/build/build-stats.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { byteSize, sortBy } from '@utils';
import { byteSize, isOutputTargetStats, sortBy } from '@utils';

import type * as d from '../../declarations';
import { isOutputTargetStats } from '../output-targets/output-utils';

/**
* Generates the Build Stats from the buildCtx. Writes any files to the file system.
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/bundle/ext-transforms-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { hasError, normalizeFsPath } from '@utils';
import { hasError, isOutputTargetDistCollection, normalizeFsPath } from '@utils';
import { join, relative } from 'path';
import type { Plugin } from 'rollup';

import type * as d from '../../declarations';
import { isOutputTargetDistCollection } from '../output-targets/output-utils';
import { runPluginTransformsEsmImports } from '../plugin/plugin';
import { parseImportPath } from '../transformers/stencil-import-path';
import type { BundleOptions } from './bundle-interface';
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/bundle/server-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { isString, normalizeFsPath } from '@utils';
import { isOutputTargetHydrate, isString, normalizeFsPath } from '@utils';
import { isAbsolute } from 'path';
import type { Plugin } from 'rollup';

import type * as d from '../../declarations';
import { isOutputTargetHydrate } from '../output-targets/output-utils';

export const serverPlugin = (config: d.ValidatedConfig, platform: string): Plugin => {
const isHydrateBundle = platform === 'hydrate';
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/config/outputs/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { buildError } from '@utils';
import { buildError, isValidConfigOutputTarget, VALID_CONFIG_OUTPUT_TARGETS } from '@utils';

import type * as d from '../../../declarations';
import { isValidConfigOutputTarget, VALID_CONFIG_OUTPUT_TARGETS } from '../../output-targets/output-utils';
import { validateCollection } from './validate-collection';
import { validateCustomElement } from './validate-custom-element';
import { validateCustomOutput } from './validate-custom-output';
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/config/outputs/validate-collection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isOutputTargetDistCollection } from '@utils';

import type * as d from '../../../declarations';
import { isOutputTargetDistCollection } from '../../output-targets/output-utils';
import { getAbsolutePath } from '../config-utils';

/**
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/config/outputs/validate-custom-element.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isBoolean } from '@utils';
import { COPY, DIST_TYPES, isBoolean, isOutputTargetDistCustomElements } from '@utils';
import { join } from 'path';

import type {
Expand All @@ -9,7 +9,6 @@ import type {
ValidatedConfig,
} from '../../../declarations';
import { CustomElementsExportBehaviorOptions } from '../../../declarations';
import { COPY, DIST_TYPES, isOutputTargetDistCustomElements } from '../../output-targets/output-utils';
import { getAbsolutePath } from '../config-utils';
import { validateCopy } from '../validate-copy';

Expand Down
3 changes: 1 addition & 2 deletions src/compiler/config/outputs/validate-custom-output.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { catchError } from '@utils';
import { catchError, COPY, isOutputTargetCustom } from '@utils';

import type * as d from '../../../declarations';
import { COPY, isOutputTargetCustom } from '../../output-targets/output-utils';

export const validateCustomOutput = (
config: d.ValidatedConfig,
Expand Down
11 changes: 6 additions & 5 deletions src/compiler/config/outputs/validate-dist.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import { isBoolean, isString } from '@utils';
import { isAbsolute, join, resolve } from 'path';

import type * as d from '../../../declarations';
import {
COPY,
DIST_COLLECTION,
Expand All @@ -10,8 +6,13 @@ import {
DIST_LAZY_LOADER,
DIST_TYPES,
getComponentsDtsTypesFilePath,
isBoolean,
isOutputTargetDist,
} from '../../output-targets/output-utils';
isString,
} from '@utils';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we combine this with the existing @utils import?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, thought I captured all of those!

import { isAbsolute, join, resolve } from 'path';

import type * as d from '../../../declarations';
import { getAbsolutePath } from '../config-utils';
import { validateCopy } from '../validate-copy';

Expand Down
14 changes: 8 additions & 6 deletions src/compiler/config/outputs/validate-docs.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { buildError, isFunction, isString } from '@utils';
import { isAbsolute, join } from 'path';

import type * as d from '../../../declarations';
import { NOTE } from '../../docs/constants';
import {
buildError,
isFunction,
isOutputTargetDocsCustom,
isOutputTargetDocsJson,
isOutputTargetDocsReadme,
isOutputTargetDocsVscode,
} from '../../output-targets/output-utils';
isString,
} from '@utils';
import { isAbsolute, join } from 'path';

import type * as d from '../../../declarations';
import { NOTE } from '../../docs/constants';

export const validateDocs = (config: d.ValidatedConfig, diagnostics: d.Diagnostic[], userOutputs: d.OutputTarget[]) => {
const docsOutputs: d.OutputTarget[] = [];
Expand Down
11 changes: 6 additions & 5 deletions src/compiler/config/outputs/validate-hydrate-script.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { isBoolean, isString } from '@utils';
import { isAbsolute, join } from 'path';

import type * as d from '../../../declarations';
import {
DIST_HYDRATE_SCRIPT,
isBoolean,
isOutputTargetDist,
isOutputTargetHydrate,
isOutputTargetWww,
} from '../../output-targets/output-utils';
isString,
} from '@utils';
import { isAbsolute, join } from 'path';

import type * as d from '../../../declarations';
import { NODE_BUILTINS } from '../../sys/modules';

export const validateHydrateScript = (config: d.ValidatedConfig, userOutputs: d.OutputTarget[]) => {
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/config/outputs/validate-lazy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { isBoolean } from '@utils';
import { DIST_LAZY, isBoolean, isOutputTargetDistLazy } from '@utils';
import { join } from 'path';

import type * as d from '../../../declarations';
import { DIST_LAZY, isOutputTargetDistLazy } from '../../output-targets/output-utils';
import { getAbsolutePath } from '../config-utils';

export const validateLazy = (config: d.ValidatedConfig, userOutputs: d.OutputTarget[]) => {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/config/outputs/validate-stats.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isOutputTargetStats, STATS } from '@utils';
import { isAbsolute, join } from 'path';

import type * as d from '../../../declarations';
import { isOutputTargetStats, STATS } from '../../output-targets/output-utils';

export const validateStats = (userConfig: d.ValidatedConfig, userOutputs: d.OutputTarget[]) => {
const outputTargets: d.OutputTargetStats[] = [];
Expand Down
12 changes: 7 additions & 5 deletions src/compiler/config/outputs/validate-www.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { buildError, isBoolean, isString } from '@utils';
import { isAbsolute, join } from 'path';

import type * as d from '../../../declarations';
import {
buildError,
COPY,
DIST_GLOBAL_STYLES,
DIST_LAZY,
isBoolean,
isOutputTargetDist,
isOutputTargetWww,
isString,
WWW,
} from '../../output-targets/output-utils';
} from '@utils';
import { isAbsolute, join } from 'path';

import type * as d from '../../../declarations';
import { getAbsolutePath } from '../config-utils';
import { validateCopy } from '../validate-copy';
import { validatePrerender } from '../validate-prerender';
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/config/test/validate-config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type * as d from '@stencil/core/declarations';
import { mockCompilerSystem, mockLoadConfigInit, mockLogger } from '@stencil/core/testing';
import { DOCS_CUSTOM, DOCS_JSON, DOCS_README, DOCS_VSCODE } from '@utils';

import { createConfigFlags } from '../../../cli/config-flags';
import { isWatchIgnorePath } from '../../fs-watch/fs-watch-rebuild';
import { DOCS_CUSTOM, DOCS_JSON, DOCS_README, DOCS_VSCODE } from '../../output-targets/output-utils';
import { validateConfig } from '../validate-config';

describe('validation', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type * as d from '@stencil/core/declarations';
import { mockConfig, mockLoadConfigInit } from '@stencil/core/testing';
import { COPY, DIST_CUSTOM_ELEMENTS, DIST_TYPES } from '@utils';
import path from 'path';

import { COPY, DIST_CUSTOM_ELEMENTS, DIST_TYPES } from '../../output-targets/output-utils';
import { validateConfig } from '../validate-config';

describe('validate-output-dist-custom-element', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/config/test/validate-output-www.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type * as d from '@stencil/core/declarations';
import { mockLoadConfigInit } from '@stencil/core/testing';
import { isOutputTargetCopy, isOutputTargetHydrate, isOutputTargetWww } from '@utils';
import path from 'path';

import { ConfigFlags, createConfigFlags } from '../../../cli/config-flags';
import { isOutputTargetCopy, isOutputTargetHydrate, isOutputTargetWww } from '../../output-targets/output-utils';
import { validateConfig } from '../validate-config';

describe('validateOutputTargetWww', () => {
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/config/validate-dev-server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { buildError, isBoolean, isNumber, isString, normalizePath } from '@utils';
import { buildError, isBoolean, isNumber, isOutputTargetWww, isString, normalizePath } from '@utils';
import { isAbsolute, join } from 'path';

import type * as d from '../../declarations';
import { isOutputTargetWww } from '../output-targets/output-utils';

export const validateDevServer = (
config: d.ValidatedConfig,
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/config/validate-namespace.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { buildError, dashToPascalCase, isString } from '@utils';
import { buildError, dashToPascalCase, isOutputTargetDist, isString } from '@utils';

import type * as d from '../../declarations';
import { isOutputTargetDist } from '../output-targets/output-utils';

export const validateNamespace = (c: d.UnvalidatedConfig, diagnostics: d.Diagnostic[]) => {
c.namespace = isString(c.namespace) ? c.namespace : DEFAULT_NAMESPACE;
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/config/validate-testing.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { buildError, isString } from '@utils';
import { buildError, isOutputTargetDist, isOutputTargetWww, isString } from '@utils';
import { basename, dirname, isAbsolute, join } from 'path';

import type * as d from '../../declarations';
import { isOutputTargetDist, isOutputTargetWww } from '../output-targets/output-utils';
import { isLocalModule } from '../sys/resolve/resolve-utils';

export const validateTesting = (config: d.ValidatedConfig, diagnostics: d.Diagnostic[]) => {
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/docs/custom/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isOutputTargetDocsCustom } from '@utils';

import type * as d from '../../../declarations';
import { isOutputTargetDocsCustom } from '../../output-targets/output-utils';

export const generateCustomDocs = async (
config: d.ValidatedConfig,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/docs/json/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isOutputTargetDocsJson } from '@utils';
import { join } from 'path';

import type * as d from '../../../declarations';
import { isOutputTargetDocsJson } from '../../output-targets/output-utils';

export const generateJsonDocs = async (
config: d.ValidatedConfig,
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/docs/readme/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isOutputTargetDocsReadme } from '@utils';

import type * as d from '../../../declarations';
import { isOutputTargetDocsReadme } from '../../output-targets/output-utils';
import { generateReadme } from './output-docs';

export const generateReadmeDocs = async (
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/docs/test/generate-doc-data.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mockBuildCtx, mockCompilerCtx, mockModule, mockValidatedConfig } from '@stencil/core/testing';
import { getComponentsFromModules } from '@utils';

import type * as d from '../../../declarations';
import { getComponentsFromModules } from '../../output-targets/output-utils';
import { stubComponentCompilerMeta } from '../../types/tests/ComponentCompilerMeta.stub';
import { AUTO_GENERATE_COMMENT } from '../constants';
import { generateDocData } from '../generate-doc-data';
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/docs/vscode/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isOutputTargetDocsVscode } from '@utils';
import { join } from 'path';

import type * as d from '../../../declarations';
import { isOutputTargetDocsVscode } from '../../output-targets/output-utils';
import { getNameText } from '../generate-doc-data';

/**
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/fs-watch/fs-watch-rebuild.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { isString, unique } from '@utils';
import { isOutputTargetDocsJson, isOutputTargetDocsVscode, isOutputTargetStats, isString, unique } from '@utils';
import { basename } from 'path';

import type * as d from '../../declarations';
import { isOutputTargetDocsJson, isOutputTargetDocsVscode, isOutputTargetStats } from '../output-targets/output-utils';

export const filesChanged = (buildCtx: d.BuildCtx) => {
// files changed include updated, added and deleted
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/html/validate-manifest-json.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { buildError, buildJsonFileError } from '@utils';
import { buildError, buildJsonFileError, isOutputTargetWww } from '@utils';
import { dirname, join } from 'path';

import type * as d from '../../declarations';
import { isOutputTargetWww } from '../output-targets/output-utils';

export const validateManifestJson = (config: d.ValidatedConfig, compilerCtx: d.CompilerCtx, buildCtx: d.BuildCtx) => {
if (config.devMode) {
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/output-targets/copy/output-copy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { buildError, isGlob, normalizePath } from '@utils';
import { buildError, isGlob, isOutputTargetCopy, normalizePath } from '@utils';
import minimatch from 'minimatch';
import { join } from 'path';

import type * as d from '../../../declarations';
import { isOutputTargetCopy } from '../output-utils';
import { canSkipAssetsCopy, getComponentAssetsCopyTasks } from './assets-copy-tasks';
import { getDestAbsPath, getSrcAbsPath } from './local-copy-tasks';

Expand Down
Loading