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
19 changes: 11 additions & 8 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ import eslintConfigPrettier from "eslint-config-prettier";
import babelParser from "@babel/eslint-parser";

export default [
{
// https://github.com/eslint/eslint/discussions/18304#discussioncomment-9069706
ignores: [
".greenwood/*",
"node_modules/*",
"public/*",
"reports/*",
"storybook-static/**",
"patches/**",
],
},
{
languageOptions: {
parser: babelParser,
Expand All @@ -18,14 +29,6 @@ export default [
node: true,
},
},
ignores: [
".greenwood/*",
"node_modules/*",
"public/*",
"reports/*",
"storybook-static/**",
"patches/**",
],
rules: {
"comma-dangle": [2, "never"],
"no-cond-assign": 2,
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"@babel/plugin-syntax-import-assertions": "^7.24.1",
"@chromatic-com/storybook": "^1.3.1",
"@esm-bundle/chai": "^4.3.4-fix.0",
"@greenwood/cli": "^0.30.0-alpha.4",
"@greenwood/plugin-import-raw": "^0.30.0-alpha.4",
"@greenwood/cli": "^0.30.0-alpha.5",
"@greenwood/plugin-import-raw": "^0.30.0-alpha.5",
"@ls-lint/ls-lint": "^1.10.0",
"@mapbox/rehype-prism": "^0.9.0",
"@storybook/addon-essentials": "^8.0.6",
Expand Down
35 changes: 35 additions & 0 deletions patches/@greenwood+cli+0.30.0-alpha.5.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
diff --git a/node_modules/@greenwood/cli/src/config/rollup.config.js b/node_modules/@greenwood/cli/src/config/rollup.config.js
index 1354e66..e50e2aa 100644
--- a/node_modules/@greenwood/cli/src/config/rollup.config.js
+++ b/node_modules/@greenwood/cli/src/config/rollup.config.js
@@ -530,8 +530,8 @@ function greenwoodSyncImportAttributes(compilation) {
// since we can't do async work inside a sync AST operation
if (!asset.preBundled) {
const assetUrl = unbundledAssetsRefMapper[asset].sourceURL;
- const request = new Request(assetUrl, { headers: { 'Content-Type': 'text/css' } });
- let response = new Response(unbundledAssetsRefMapper[asset].source);
+ const request = new Request(assetUrl, { headers: { 'Accept': 'text/css' } });
+ let response = new Response(unbundledAssetsRefMapper[asset].source, { headers: { 'Content-Type': 'text/css' } });

for (const plugin of resourcePlugins) {
if (plugin.shouldPreIntercept && await plugin.shouldPreIntercept(assetUrl, request, response.clone())) {
diff --git a/node_modules/@greenwood/cli/src/plugins/resource/plugin-standard-css.js b/node_modules/@greenwood/cli/src/plugins/resource/plugin-standard-css.js
index d8409ea..27bfbce 100644
--- a/node_modules/@greenwood/cli/src/plugins/resource/plugin-standard-css.js
+++ b/node_modules/@greenwood/cli/src/plugins/resource/plugin-standard-css.js
@@ -306,11 +306,13 @@ class StandardCssResource extends ResourceInterface {
});
}

- async shouldIntercept(url) {
+ async shouldIntercept(url, request, response) {
const { pathname } = url;
const ext = pathname.split('.').pop();

- return url.protocol === 'file:' && ext === this.extensions[0];
+ return url.protocol === 'file:'
+ && ext === this.extensions[0]
+ && (response.headers.get('Content-Type')?.indexOf('text/css') >= 0 || request.headers.get('Accept')?.indexOf('text/javascript') >= 0);
}

async intercept(url, request, response) {
22 changes: 17 additions & 5 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import path from "path";
import { greenwoodPluginStandardCss } from "@greenwood/cli/src/plugins/resource/plugin-standard-css.js";
import { greenwoodPluginImportRaw } from "@greenwood/plugin-import-raw";

const standardCssResource = greenwoodPluginStandardCss.provider({});
const rawResource = greenwoodPluginImportRaw()[0].provider({});
const compilation = {
context: {
projectDirectory: import.meta.url,
},
};
const standardCssResource = greenwoodPluginStandardCss.provider(compilation);
const rawResource = greenwoodPluginImportRaw()[0].provider(compilation);

// Vite doesn't support import attributes :/
// https://github.com/vitejs/vite/pull/15654
Expand All @@ -16,23 +21,30 @@ const rawResource = greenwoodPluginImportRaw()[0].provider({});
// https://github.com/vitejs/vite/issues/15322#issuecomment-1858878697
function transformConstructableStylesheetsPlugin() {
return {
name: "transform-css-module-scripts",
name: "transform-constructable-stylesheets",
enforce: "pre",
resolveId: (id, importer) => {
if (
importer?.indexOf("/src/components/") >= 0 &&
id.endsWith(".css") &&
!id.endsWith(".module.css")
) {
// add .type so CSS modules are not precessed by the default pipeline
// add .type so Constructable Stylesheets are not precessed by Vite's default pipeline
return path.join(path.dirname(importer), `${id}.type`);
}
},
load: async (id) => {
if (id.endsWith(".css.type")) {
const filename = id.slice(0, -5);
const contents = fs.readFileSync(filename, "utf-8");
const response = await standardCssResource.intercept(null, null, new Response(contents));
const url = new URL(`file://${id.replace(".type", "")}`);
// "coerce" native conststructable stylesheets into inline JS so Vite / Rollup do not complain
const request = new Request(url, {
headers: {
Accept: "text/javascript",
},
});
const response = await standardCssResource.intercept(url, request, new Response(contents));
const body = await response.text();

return body;
Expand Down