@stencil/core 5.0.0-rc.4 → 5.0.0-rc.6

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.
@@ -1845,7 +1845,7 @@ const validateComponentTag = (tag) => {
1845
1845
  };
1846
1846
  //#endregion
1847
1847
  //#region src/version.ts
1848
- const version = "5.0.0-rc.4";
1848
+ const version = "5.0.0-rc.6";
1849
1849
  //#endregion
1850
1850
  //#region src/compiler/events.ts
1851
1851
  const buildEvents = () => {
@@ -4140,6 +4140,7 @@ const autoprefixCss = async (cssText, opts, filePath, minify = false) => {
4140
4140
  };
4141
4141
  if (typeof e.name === "string") diagnostic.header = e.name;
4142
4142
  if (typeof e.message === "string") diagnostic.messageText = e.message;
4143
+ if (e.data?.type === "SelectorError" && e.loc && typeof e.loc.line === "number") diagnostic.messageText = getSelectorErrorMessage(typeof e.source === "string" ? e.source : cssText, e.loc, diagnostic.messageText, e.data.value?.type);
4143
4144
  if (filePath) diagnostic.absFilePath = filePath;
4144
4145
  else if (typeof e.fileName === "string" && e.fileName !== "style.css") diagnostic.absFilePath = e.fileName;
4145
4146
  if (e.loc && typeof e.loc.line === "number") {
@@ -4169,6 +4170,25 @@ const autoprefixCss = async (cssText, opts, filePath, minify = false) => {
4169
4170
  return output;
4170
4171
  };
4171
4172
  /**
4173
+ * Lightning CSS selector errors (e.g. `Invalid state`) don't name the selector, and for
4174
+ * preprocessed styles the reported line is in the compiled CSS, not the source file.
4175
+ * @param sourceText the CSS that failed to parse
4176
+ * @param loc the 1-based error location reported by Lightning CSS
4177
+ * @param loc.line the error line
4178
+ * @param loc.column the error column
4179
+ * @param message the original error message
4180
+ * @param errorType the Lightning CSS selector error type
4181
+ * @returns a message that includes the offending selector
4182
+ */
4183
+ const getSelectorErrorMessage = (sourceText, loc, message, errorType) => {
4184
+ const offset = sourceText.split("\n").slice(0, loc.line - 1).reduce((acc, line) => acc + line.length + 1, 0) + (loc.column ?? 1) - 1;
4185
+ const start = Math.max(sourceText.lastIndexOf("{", offset), sourceText.lastIndexOf("}", offset), sourceText.lastIndexOf(";", offset));
4186
+ const end = sourceText.indexOf("{", offset);
4187
+ const selector = sourceText.slice(start + 1, end === -1 ? void 0 : end).trim();
4188
+ if (!selector) return message;
4189
+ return `Invalid CSS selector "${selector}": ${message}.${errorType === "InvalidState" ? ` A pseudo-class can't follow a pseudo-element (e.g. \`::before:dir(rtl)\`); move it before (\`:dir(rtl)::before\`).` : ""}`;
4190
+ };
4191
+ /**
4172
4192
  * Default browserslist targets used when autoprefixing CSS.
4173
4193
  * Targets ES2017 browsers (2022+) only.
4174
4194
  */
@@ -1,3 +1,3 @@
1
- import { A as version, C as hasStencilHydrateImport, D as parseCssOnlyComponents, E as replaceStencilHydrateImport, M as scopeCss, O as buildId, S as hasStencilGlobalsImport, T as replaceStencilGlobalsImport, _ as cmpMetaToDocsComponent, a as createPrerenderer, b as buildHydrateCss, c as createWorkerContext, d as nodeRequire, f as optimizeCss, g as generateManifest, h as generateComponentTypesFile, i as createSystem, j as versions, k as vermoji, l as createWorkerMessageHandler, m as validateHydrated, n as transpile, o as loadConfig, p as validateConfig, r as transpileSync, s as createCompiler, t as ts, u as optimizeJs, v as getScopeId, w as replaceStencilCssComponentsImport, x as hasStencilCssComponentsImport, y as foldBuildFlags } from "../compiler-CUe9rzEa.mjs";
1
+ import { A as version, C as hasStencilHydrateImport, D as parseCssOnlyComponents, E as replaceStencilHydrateImport, M as scopeCss, O as buildId, S as hasStencilGlobalsImport, T as replaceStencilGlobalsImport, _ as cmpMetaToDocsComponent, a as createPrerenderer, b as buildHydrateCss, c as createWorkerContext, d as nodeRequire, f as optimizeCss, g as generateManifest, h as generateComponentTypesFile, i as createSystem, j as versions, k as vermoji, l as createWorkerMessageHandler, m as validateHydrated, n as transpile, o as loadConfig, p as validateConfig, r as transpileSync, s as createCompiler, t as ts, u as optimizeJs, v as getScopeId, w as replaceStencilCssComponentsImport, x as hasStencilCssComponentsImport, y as foldBuildFlags } from "../compiler-BBM6aOyJ.mjs";
2
2
  import { a as LOG_LEVELS, i as CustomElementsExportBehaviorOptions } from "../node-Bsfi3pOs.mjs";
3
3
  export { CustomElementsExportBehaviorOptions, LOG_LEVELS, buildHydrateCss, buildId, cmpMetaToDocsComponent, createCompiler, createPrerenderer, createSystem, createWorkerContext, createWorkerMessageHandler, foldBuildFlags, generateComponentTypesFile, generateManifest, getScopeId, hasStencilCssComponentsImport, hasStencilGlobalsImport, hasStencilHydrateImport, loadConfig, nodeRequire, optimizeCss, optimizeJs, parseCssOnlyComponents, replaceStencilCssComponentsImport, replaceStencilGlobalsImport, replaceStencilHydrateImport, scopeCss, transpile, transpileSync, ts, validateConfig, validateHydrated, vermoji, version, versions };
@@ -461,9 +461,9 @@ const scopeCss = (cssText, scopeId, commentOriginalSelector) => {
461
461
  };
462
462
  //#endregion
463
463
  //#region src/version.ts
464
- const version = "5.0.0-rc.4";
465
- const buildId = "1795120176";
466
- const vermoji = "🐶";
464
+ const version = "5.0.0-rc.6";
465
+ const buildId = "1795174424";
466
+ const vermoji = "🚨";
467
467
  /**
468
468
  * Get the installed version of a tool/dependency.
469
469
  * Handles packages with exports maps that point to subdirectories.
@@ -2065,28 +2065,40 @@ const scanFiles = async (config, compilerCtx, buildCtx, cache, filePaths) => {
2065
2065
  }));
2066
2066
  };
2067
2067
  /**
2068
- * Load a CSS-only component source file's text. A plain `.css` file is read as-is; any other
2069
- * `STYLE_EXT` extension is run through the configured `plugins` first (e.g. `@stencil/sass`
2070
- * compiling `.scss` to CSS) - the same pipeline `collectCssOnlyComponentStyles` uses to emit
2071
- * this file's CSS, so discovery parses exactly what gets shipped.
2068
+ * Load a CSS-only component source file's text. Only files whose raw source contains
2069
+ * `@component` are considered - a definition belongs to the file that literally contains it,
2070
+ * so preprocessor partials and importers are never compiled standalone here. A plain `.css`
2071
+ * file is returned as-is; any other `STYLE_EXT` extension is run through the configured
2072
+ * `plugins` first (e.g. `@stencil/sass` compiling `.scss` to CSS) - the same pipeline
2073
+ * `collectCssOnlyComponentStyles` uses to emit this file's CSS, so discovery parses exactly
2074
+ * what gets shipped.
2072
2075
  *
2073
2076
  * @param config the validated Stencil config
2074
2077
  * @param compilerCtx the compiler context, used to read the file and register watch files
2075
2078
  * @param buildCtx the current build context, used for plugin transform diagnostics
2076
2079
  * @param filePath absolute path to the source file to load
2077
- * @returns the (possibly preprocessed) CSS text, or `null` if the file couldn't be loaded
2080
+ * @returns the (possibly preprocessed) CSS text, or `null` if the file couldn't be loaded or
2081
+ * has no `@component` marker
2078
2082
  */
2079
2083
  const loadCssOnlyComponentSource = async (config, compilerCtx, buildCtx, filePath) => {
2080
- if (filePath.toLowerCase().endsWith(".css")) try {
2081
- return await compilerCtx.fs.readFile(filePath);
2084
+ let rawText;
2085
+ try {
2086
+ rawText = await compilerCtx.fs.readFile(filePath);
2082
2087
  } catch {
2083
2088
  return null;
2084
2089
  }
2090
+ if (!rawText.includes("@component")) return null;
2091
+ if (filePath.toLowerCase().endsWith(".css")) return rawText;
2085
2092
  const transformResults = await runPluginTransforms(config, compilerCtx, buildCtx, filePath);
2086
2093
  if (!transformResults) return null;
2087
- if (typeof transformResults === "string") return transformResults;
2088
- for (const dep of transformResults.dependencies ?? []) compilerCtx.addWatchFile(dep);
2089
- return transformResults.code ?? null;
2094
+ const code = typeof transformResults === "string" ? transformResults : transformResults.code;
2095
+ if (typeof transformResults !== "string") for (const dep of transformResults.dependencies ?? []) compilerCtx.addWatchFile(dep);
2096
+ if (code != null && !code.includes("@component")) {
2097
+ const warn = buildWarn(buildCtx.diagnostics);
2098
+ warn.messageText = `"${relative$1(config.rootDir, filePath)}" contains "@component" but its preprocessed output does not, so no CSS-only components were discovered in it. Is the preprocessor stripping comments (e.g. sass \`outputStyle: 'compressed'\`)?`;
2099
+ warn.absFilePath = filePath;
2100
+ }
2101
+ return code ?? null;
2090
2102
  };
2091
2103
  const flattenCache = (cache) => Array.from(cache.values()).flat();
2092
2104
  /**
@@ -7983,6 +7995,31 @@ const generateRolldownOutput = async (build, options, config, entryModules) => {
7983
7995
  });
7984
7996
  };
7985
7997
  //#endregion
7998
+ //#region src/compiler/output-targets/dist-lazy/cjs-import-meta-url-plugin.ts
7999
+ /**
8000
+ * With `platform: 'browser'` (shared with the ESM output), Rolldown renders `import.meta.url`
8001
+ * in CJS as `{}.url`. Replace it with the same expression Rolldown emits for `platform: 'node'`.
8002
+ */
8003
+ const EMPTY_IMPORT_META_URL = /\{\}\.url\b/g;
8004
+ const CJS_FILE_URL = `require("url").pathToFileURL(__filename).href`;
8005
+ /**
8006
+ * A Rolldown output plugin that restores `import.meta.url` in CJS chunks.
8007
+ * @param sourceMap whether to generate a source map for the replacement
8008
+ * @returns a Rolldown plugin
8009
+ */
8010
+ const cjsImportMetaUrlPlugin = (sourceMap) => ({
8011
+ name: "cjsImportMetaUrlPlugin",
8012
+ renderChunk(code) {
8013
+ if (!code.includes("{}.url")) return null;
8014
+ const s = new MagicString(code);
8015
+ s.replaceAll(EMPTY_IMPORT_META_URL, CJS_FILE_URL);
8016
+ return {
8017
+ code: s.toString(),
8018
+ map: sourceMap ? s.generateMap({ hires: true }) : null
8019
+ };
8020
+ }
8021
+ });
8022
+ //#endregion
7986
8023
  //#region src/compiler/output-targets/dist-lazy/write-lazy-entry-module.ts
7987
8024
  const writeLazyModule = async (compilerCtx, outputTargetType, destinations, code, sourceMap, rolldownResult) => {
7988
8025
  const fileName = rolldownResult.fileName;
@@ -8325,7 +8362,7 @@ const generateCjs = async (config, compilerCtx, buildCtx, rolldownBuild, outputT
8325
8362
  entryFileNames: "[name].cjs",
8326
8363
  assetFileNames: "[name]-[hash][extname]",
8327
8364
  ...getRolldownSourceMapOptions(config),
8328
- plugins: [lazyBundleIdPlugin(buildCtx, config, false, 8, ".cjs")]
8365
+ plugins: [lazyBundleIdPlugin(buildCtx, config, false, 8, ".cjs"), cjsImportMetaUrlPlugin(!!config.sourceMap)]
8329
8366
  };
8330
8367
  if (config.compat.enableImportInjection) esmOpts.dynamicImportInCjs = false;
8331
8368
  const results = await generateRolldownOutput(rolldownBuild, esmOpts, config, buildCtx.entryModules);
@@ -8333,6 +8370,7 @@ const generateCjs = async (config, compilerCtx, buildCtx, rolldownBuild, outputT
8333
8370
  const destinations = cjsOutputs.map((o) => o.cjsDir).filter((cjsDir) => typeof cjsDir === "string");
8334
8371
  buildCtx.commonJsComponentBundle = await generateLazyModules(config, compilerCtx, buildCtx, outputTargetType, destinations, results, "es2022", false);
8335
8372
  await generateShortcuts$1(compilerCtx, results, cjsOutputs);
8373
+ await writeCjsPackageJson(compilerCtx, cjsOutputs);
8336
8374
  }
8337
8375
  }
8338
8376
  return {
@@ -8340,6 +8378,14 @@ const generateCjs = async (config, compilerCtx, buildCtx, rolldownBuild, outputT
8340
8378
  buildCtx
8341
8379
  };
8342
8380
  };
8381
+ /**
8382
+ * Chunks and lazy entries in the CJS dir keep a `.js` extension, so scope them as CommonJS
8383
+ * in case the consuming package sets `"type": "module"`.
8384
+ * @param compilerCtx the current compiler context
8385
+ * @param outputTargets the output targets with a CJS dir
8386
+ * @returns a promise that resolves once each `package.json` is written
8387
+ */
8388
+ const writeCjsPackageJson = (compilerCtx, outputTargets) => Promise.all(outputTargets.map((o) => compilerCtx.fs.writeFile(join$2(o.cjsDir, "package.json"), `{"type":"commonjs"}\n`, { outputTargetType: o.type })));
8343
8389
  const generateShortcuts$1 = (compilerCtx, rolldownResult, outputTargets) => {
8344
8390
  const indexFilename = rolldownResult.find((r) => r.type === "chunk" && r.isIndex).fileName;
8345
8391
  return Promise.all(outputTargets.map(async (o) => {
@@ -20474,7 +20520,7 @@ const validateFilesField = async (config, compilerCtx, buildCtx) => {
20474
20520
  const packageJsonDir = dirname$1(config.packageJsonFilePath);
20475
20521
  const absPath = join$2(packageJsonDir, pkgFile);
20476
20522
  if (!await compilerCtx.fs.access(absPath)) {
20477
- const msg = `Unable to find "${pkgFile}" within the package.json "files" array.`;
20523
+ const msg = `"${pkgFile}" is listed in the package.json "files" array but could not be found on disk.`;
20478
20524
  packageJsonError(config, compilerCtx, buildCtx, msg, `"${pkgFile}"`);
20479
20525
  }
20480
20526
  }
@@ -23867,6 +23913,7 @@ const autoprefixCss = async (cssText, opts, filePath, minify = false) => {
23867
23913
  };
23868
23914
  if (typeof e.name === "string") diagnostic.header = e.name;
23869
23915
  if (typeof e.message === "string") diagnostic.messageText = e.message;
23916
+ if (e.data?.type === "SelectorError" && e.loc && typeof e.loc.line === "number") diagnostic.messageText = getSelectorErrorMessage(typeof e.source === "string" ? e.source : cssText, e.loc, diagnostic.messageText, e.data.value?.type);
23870
23917
  if (filePath) diagnostic.absFilePath = filePath;
23871
23918
  else if (typeof e.fileName === "string" && e.fileName !== "style.css") diagnostic.absFilePath = e.fileName;
23872
23919
  if (e.loc && typeof e.loc.line === "number") {
@@ -23896,6 +23943,25 @@ const autoprefixCss = async (cssText, opts, filePath, minify = false) => {
23896
23943
  return output;
23897
23944
  };
23898
23945
  /**
23946
+ * Lightning CSS selector errors (e.g. `Invalid state`) don't name the selector, and for
23947
+ * preprocessed styles the reported line is in the compiled CSS, not the source file.
23948
+ * @param sourceText the CSS that failed to parse
23949
+ * @param loc the 1-based error location reported by Lightning CSS
23950
+ * @param loc.line the error line
23951
+ * @param loc.column the error column
23952
+ * @param message the original error message
23953
+ * @param errorType the Lightning CSS selector error type
23954
+ * @returns a message that includes the offending selector
23955
+ */
23956
+ const getSelectorErrorMessage = (sourceText, loc, message, errorType) => {
23957
+ const offset = sourceText.split("\n").slice(0, loc.line - 1).reduce((acc, line) => acc + line.length + 1, 0) + (loc.column ?? 1) - 1;
23958
+ const start = Math.max(sourceText.lastIndexOf("{", offset), sourceText.lastIndexOf("}", offset), sourceText.lastIndexOf(";", offset));
23959
+ const end = sourceText.indexOf("{", offset);
23960
+ const selector = sourceText.slice(start + 1, end === -1 ? void 0 : end).trim();
23961
+ if (!selector) return message;
23962
+ return `Invalid CSS selector "${selector}": ${message}.${errorType === "InvalidState" ? ` A pseudo-class can't follow a pseudo-element (e.g. \`::before:dir(rtl)\`); move it before (\`:dir(rtl)::before\`).` : ""}`;
23963
+ };
23964
+ /**
23899
23965
  * Default browserslist targets used when autoprefixing CSS.
23900
23966
  * Targets ES2017 browsers (2022+) only.
23901
23967
  */
@@ -1,4 +1,4 @@
1
- import { l as createWorkerMessageHandler } from "../../compiler-CUe9rzEa.mjs";
1
+ import { l as createWorkerMessageHandler } from "../../compiler-BBM6aOyJ.mjs";
2
2
  import { t as createNodeSys } from "../../node-Bsfi3pOs.mjs";
3
3
  //#region src/sys/node/node-worker-thread.ts
4
4
  /**
@@ -33,7 +33,7 @@ import "@rollup/pluginutils";
33
33
  import { createHash } from "crypto";
34
34
  import { afterAll, vi } from "vitest";
35
35
  //#region src/version.ts
36
- const version = "5.0.0-rc.4";
36
+ const version = "5.0.0-rc.6";
37
37
  const MEMBER_FLAGS = {
38
38
  String: 1,
39
39
  Number: 2,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/core",
3
- "version": "5.0.0-rc.4",
3
+ "version": "5.0.0-rc.6",
4
4
  "description": "A Compiler for Web Components and Progressive Web Apps",
5
5
  "keywords": [
6
6
  "components",
@@ -126,9 +126,9 @@
126
126
  "terser": "^5.50.0",
127
127
  "tinyglobby": "^0.2.17",
128
128
  "typescript": ">5.0.0 <7.0.0",
129
- "@stencil/cli": "5.0.0-rc.4",
130
- "@stencil/dev-server": "5.0.0-rc.4",
131
- "@stencil/mock-doc": "5.0.0-rc.4"
129
+ "@stencil/cli": "5.0.0-rc.6",
130
+ "@stencil/mock-doc": "5.0.0-rc.6",
131
+ "@stencil/dev-server": "5.0.0-rc.6"
132
132
  },
133
133
  "devDependencies": {
134
134
  "@ionic/prettier-config": "^4.0.0",