@arcgis/lumina-compiler 4.34.0-next.90 → 4.34.0-next.96

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.
@@ -9,7 +9,12 @@ export declare const defaultHydratedAttribute = "hydrated";
9
9
  * @see https://discord.com/channels/1012791295170859069/1274527043614150708
10
10
  */
11
11
  export declare function getGlobalCssInjectionCode(globalCssString: string | undefined, context: CompilerContext): string;
12
- /**
12
+ /**a
13
13
  * Get a CSS string that can be printed into a .css file
14
+ *
15
+ * Global CSS is auto-imported by bundlers. To ensure it is always loaded with
16
+ * lower precedence order than user styles, we wrap it in `@layer{}`.
17
+ *
18
+ * @see https://devtopia.esri.com/WebGIS/arcgis-web-components/discussions/1824#discussioncomment-12625
14
19
  */
15
20
  export declare const getGlobalCssAsString: (context: CompilerContext) => string;
@@ -1,6 +1,22 @@
1
1
  import { Plugin } from 'vite';
2
2
  import { CompilerContext } from '../context';
3
+ /**
4
+ * CSS extension list taken from https://github.com/vitejs/vite/blob/a8c7083a3d7d7fe2e83e994ff008f39ee4f298f8/packages/vite/src/node/constants.ts#L50
5
+ */
3
6
  export declare const cssLangsRe: RegExp;
7
+ /**
8
+ * A flag added by Lumina at compile time to named CSS imports to turn
9
+ * them into Lit css`` tagged template literals (using `styles` named import).
10
+ *
11
+ * We do not automatically process every CSS file to allow for both:
12
+ * - keeping side-effect CSS imports inside external library code as is
13
+ * - tricky to do using resolveId() because ESBuild is used for some files in
14
+ * dev server.
15
+ * - explicitly importing external library's CSS as Lit css into shadow root
16
+ * - example: monaco or ckeditor styles, but attached into shadow root, rather
17
+ * than global
18
+ */
19
+ export declare const litCssFlag = "?litCss";
4
20
  /**
5
21
  * The `.adoptedStyleSheets` API is very convenient, but it has one issue: it
6
22
  * has higher precedence order than the `<link>` or `<style>` tags. This API was
@@ -12,18 +28,42 @@ export declare const cssLangsRe: RegExp;
12
28
  * More information:
13
29
  * https://discord.com/channels/1012791295170859069/1274527043614150708
14
30
  */
15
- export declare const layeredCssFlag = "?layered";
31
+ export declare const layeredLitCssFlag = "?layeredLitCss";
16
32
  /**
17
- * During build, we insert a side-effect import into the loader.ts file purely
18
- * so that the transform() is triggered for that file so that we can piggy back
19
- * on the transformed output (and create a separate .css file out of it). We do
20
- * not intend for such file to be included in the JS bundle in the NPM build.
21
- * Such import will be dropped by the minifier.
22
- *
23
- * It's a bit hacky, but that is needed to workaround this Vite behavior:
24
- * https://github.com/vitejs/vite/pull/11469#:~:text=Further%2C%20this.load%20is%20supposed%20to%20trigger%20transform%20and%20moduleParsed%20%2D%20this%20does%20not%20(in%20accordance%20with%20vite%27s%20on%2Ddemand%20nature
33
+ * Vite's library mode has CSS support (https://vite.dev/guide/build.html#css-support).
34
+ * However, if global css file references assets, the library mode will insert
35
+ * the assets base path in the CSS file. This does not work for us since the
36
+ * asset path is determined at runtime - provided by the user.
37
+ *
38
+ * Additionally, Vite's library mode css handling does not quite fit our use case:
39
+ * - We need to transform the global CSS to add hydrate CSS
40
+ * - Trickier given that we need to emit hydrate CSS even if user did not
41
+ * provide global css
42
+ * - Vite has css chunking support, which we don't need
43
+ * - We need to add an import for our CSS file (and those of libraries we are
44
+ * consuming) in runtime.ts, without processing the external CSS files
45
+ *
46
+ * It is possible to make Vite's library mode css work, but requires too much
47
+ * effort. Instead, we are bypassing Vite's global CSS handling and doing the
48
+ * simple handling sufficient for our single global css file:
49
+ * - During build, we insert a import into the loader.ts file purely
50
+ * so that the transform() is triggered for that file so that we can piggy back
51
+ * on the transformed output (and create a separate .css file out of it).
52
+ * Such import has no side-effects and is removed by Rollup.
53
+ *
54
+ * This is the only way to trigger the CSS transform without getting it added
55
+ * to the bundle because of this Vite behavior:
56
+ * https://github.com/vitejs/vite/pull/11469#:~:text=Further%2C%20this.load%20is%20supposed%20to%20trigger%20transform%20and%20moduleParsed%20%2D%20this%20does%20not%20(in%20accordance%20with%20vite%27s%20on%2Ddemand%20nature
57
+ * - We manually write dist/main.css based on hydrate CSS and global CSS.
58
+ * - During generateBundle() stage, we transform the emitted chunks/runtime.js
59
+ * to add the import to global CSS for our library and web component libraries
60
+ * we are consuming. We do this in generateBundle() stage so that such imports
61
+ * are not processed by bundler. Additionally, our loadLitCss plugin's
62
+ * transform() has a detection of side-effect CSS imports to error for them
63
+ * saying they should be import as named to be added to the shadow root - by
64
+ * doing this in generateBundle(), we bypass that check.
25
65
  */
26
- export declare const globalCssFlag = "?global";
66
+ export declare const globalCssFileFlag = "?globalFileLitCss";
27
67
  /**
28
68
  * Given a CSS file like:
29
69
  *
@@ -507,59 +507,6 @@ export type CssHandlingOptions = {
507
507
  * @default "hydrated"
508
508
  */
509
509
  hydratedAttribute?: string;
510
- /**
511
- * By default, if a side effect CSS import is detected, an error will thrown.
512
- * This is due to the requirement of handling shadow DOM styling.
513
- * Instead, you should import the "styles" variable from the .css file and add
514
- * it to your component.
515
- *
516
- * If there is a side effect CSS import from a file you don't control (i.e a
517
- * library you are using), then assign this property to a function that would
518
- * return "drop" to ignore those imports. In such case, you will be
519
- * responsible for manually providing the styles to the web component.
520
- *
521
- * If neither of these is satisfactory, a more complex solution can be
522
- * implemented in the future.
523
- *
524
- * @remarks
525
- * In regular codebases, it's common to have an import statement like so:
526
- * ```ts
527
- * import 'some-library/styles.css';
528
- * ```
529
- *
530
- * Doing so in a web component codebase is a bit trickier as the styles
531
- * need to be attached not to the `<head>` of the page, but to the shadow
532
- * root of the component that imported it. Doing so for transitive imports
533
- * is even trickier (if your component imported a .js file, which in turn
534
- * imported a .css file) as dependency tracking becomes necessary.
535
- *
536
- * That is why, for now, css imports need to be handled like so:
537
- *
538
- * - If import is originating from a file you control (your component file),
539
- * import the "styles" variable from the css file:
540
- *
541
- * ```ts
542
- * import { styles } from 'some-library/styles.css';
543
- * ```
544
- *
545
- * And then add it to your component
546
- *
547
- * ```ts
548
- * export class MyComponent extends LitElement {
549
- * static override styles = styles;
550
- * }
551
- * ```
552
- *
553
- * - If the import is originating from a file you don't control (i.e a library
554
- * code), you have to set this property to a function that will return
555
- * "drop" for a given library import to ignore such import, and then you
556
- * will have to manually provide the CSS file by importing "styles"
557
- * variable.
558
- *
559
- * @default () => "throwError"
560
- *
561
- */
562
- readonly sideEffectImportHandling?: (specifier: string, importer: string) => "drop" | "throwError";
563
510
  };
564
511
  export type AssetHandlingOptions = {
565
512
  /**
@@ -1,3 +1,13 @@
1
1
  import { CompilerContext } from '../context';
2
2
  import { TransformResult } from 'vite';
3
3
  export declare function injectRuntimeOptions(runtimeTsCode: string, context: CompilerContext): TransformResult;
4
+ /**
5
+ * Add to chunks/runtime.js import statement for the global CSS file.
6
+ * This way CSS is injected automatically, simplifying get started instructions.
7
+ * We also inject CSS imports for Lumina dependencies this package uses - this
8
+ * is needed to ensure CSS is loaded in correct order - this does not cause
9
+ * duplicate CSS bundling.
10
+ *
11
+ * Research notes: https://devtopia.esri.com/WebGIS/arcgis-web-components/discussions/1824#discussioncomment-12625
12
+ */
13
+ export declare function getGlobalCssImport(context: CompilerContext): string;
@@ -6,9 +6,3 @@ import { CompilerContext } from '../context';
6
6
  * the resulting source file
7
7
  */
8
8
  export declare function runTransformers(context: CompilerContext, transformationContext: ts.TransformationContext, sourceFile: ts.SourceFile, transformers: readonly FileTransformer[]): ts.SourceFile;
9
- /**
10
- * For performance reasons, to avoid the need to re-create the source map
11
- * after this change, replace the given code string with a comment string of
12
- * equal length :)
13
- */
14
- export declare const commentOutCode: (match: string) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/lumina-compiler",
3
- "version": "4.34.0-next.90",
3
+ "version": "4.34.0-next.96",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -18,9 +18,9 @@
18
18
  ],
19
19
  "license": "SEE LICENSE IN LICENSE.md",
20
20
  "dependencies": {
21
- "@arcgis/api-extractor": "4.34.0-next.90",
22
- "@arcgis/components-build-utils": "4.34.0-next.90",
23
- "@arcgis/toolkit": "4.34.0-next.90",
21
+ "@arcgis/api-extractor": "4.34.0-next.96",
22
+ "@arcgis/components-build-utils": "4.34.0-next.96",
23
+ "@arcgis/toolkit": "4.34.0-next.96",
24
24
  "chalk": "^5.4.1",
25
25
  "esbuild": "^0.25.5",
26
26
  "glob": "^11.0.3",
@@ -31,7 +31,7 @@
31
31
  "vitest-fail-on-console": "^0.7.1"
32
32
  },
33
33
  "peerDependencies": {
34
- "@arcgis/lumina": "~4.34.0-next.90",
34
+ "@arcgis/lumina": "~4.34.0-next.96",
35
35
  "lit": "^3.3.0",
36
36
  "typescript": "~5.8.3",
37
37
  "vite": "^7.0.0",