Skip to content
Draft
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
36 changes: 36 additions & 0 deletions .github/workflows/ci-bun-loaders.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Continuous Integration - Bun (Loaders)

on: [pull_request]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node: [24]

steps:
- name: Clone repository
uses: actions/checkout@v4

# still using Yarn since we specifically rely on Yarn workspaces
- name: Setup Node.js ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- name: Install Bun
uses: oven-sh/setup-bun@v2

- name: Disable Strict SSL
run: yarn config set strict-ssl false

- name: Install Dependencies
run: yarn install --frozen-lockfile

- name: Test
run: bun run --bun test:bun:loaders

- name: Build
run: bun run --bun build
37 changes: 37 additions & 0 deletions .github/workflows/ci-bun.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Continuous Integration - Bun
on:
pull_request:
branches: master

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node: [24]

steps:
- name: Clone repository
uses: actions/checkout@v4

# still using Yarn since we specifically rely on Yarn workspaces
- name: Setup Node.js ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

- name: Install Bun
uses: oven-sh/setup-bun@v2

- name: Disable Strict SSL
run: yarn config set strict-ssl false

- name: Install Dependencies
run: yarn install --frozen-lockfile

- name: Test
run: bun run --bun test:bun

- name: Build
run: bun run --bun build
2 changes: 1 addition & 1 deletion .mocharc.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
timeout: 90000,
timeout: 540000,
};
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"test": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=true __GWD_ROLLUP_MODE__=strict NODE_NO_WARNINGS=1 c8 mocha --exclude \"./packages/**/test/cases/loaders-*/**\" \"./packages/**/**/*.spec.js\"",
"test:loaders": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=true __GWD_ROLLUP_MODE__=strict NODE_NO_WARNINGS=1 node --import $(pwd)/test/test-register.js ./node_modules/mocha/bin/mocha \"./packages/**/**/*.spec.js\"",
"test:loaders:win": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=true __GWD_ROLLUP_MODE__=strict NODE_NO_WARNINGS=1 node --import file:\\\\%cd%\\test\\test-register.js ./node_modules/mocha/bin/mocha --exclude \"./packages/init/test/cases/**\" \"./packages/**/**/*.spec.js\"",
"test:bun": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=true __GWD_ROLLUP_MODE__=strict NODE_NO_WARNINGS=1 mocha --exclude \"./packages/**/test/cases/loaders-*/**\" \"./packages/**/**/*.spec.js\"",
"test:bun:loaders": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=true __GWD_ROLLUP_MODE__=strict NODE_NO_WARNINGS=1 node --import $(pwd)/test/test-register.js ./node_modules/mocha/bin/mocha \"./packages/**/**/*.spec.js\"",
"test:tdd": "yarn test --watch",
"lint": "yarn run lint:ls && yarn run lint:js && yarn run lint:types",
"lint:js": "eslint",
Expand All @@ -34,6 +36,9 @@
"format:check": "prettier . --check",
"prepare": "husky"
},
"trustedDependencies": [
"puppeteer"
],
"devDependencies": {
"@babel/core": "^7.24.4",
"@babel/eslint-parser": "^7.25.7",
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/lib/resource-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ function normalizePathnameForWindows(url) {
}

async function checkResourceExists(url) {
if (url.pathname === "/") {
return false;
}

try {
await fs.access(url);
return true;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/walker-package-ranger.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async function walkExportPatterns(dependency, condition, resolvedRoot) {
// https://app.unpkg.com/[email protected]/files/package.json
const needle = condition.endsWith("/*") ? `${condition}*` : condition;
const matches = fs.promises.glob(needle.startsWith("/") ? needle.replace("/", "") : needle, {
cwd: new URL(resolvedRoot),
cwd: new URL(resolvedRoot).pathname,
});

for await (const match of matches) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/plugins/resource/plugin-active-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class ContentAsDataResource {
async shouldOptimize(url, response) {
const { activeContent } = this.compilation.config;

return response.headers.get("Content-Type").indexOf(this.contentType[0]) >= 0 && activeContent;
return response.headers.get("Content-Type")?.indexOf(this.contentType[0]) >= 0 && activeContent;
}

async optimize(url, response) {
Expand Down
13 changes: 9 additions & 4 deletions packages/cli/src/plugins/resource/plugin-node-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,22 @@ class NodeModulesResource {
}

async shouldServe(url) {
const { href, protocol } = url;
const { href, protocol, pathname } = url;

return protocol === "file:" && (await checkResourceExists(new URL(href)));
return (
protocol === "file:" &&
pathname.indexOf("/node_modules/") >= 0 &&
(await checkResourceExists(new URL(href)))
);
}

async serve(url) {
async serve(url, request) {
const body = await fs.readFile(url, "utf-8");
const contentType = request.headers.get("content-type") ?? this.contentType;

return new Response(body, {
headers: new Headers({
"Content-Type": this.contentType,
"Content-Type": contentType,
}),
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,30 +166,38 @@ describe("Build Greenwood With: ", function () {
expect(linkItems.length).to.equal(2);
});

// we _technically_ can't assume the order of pages but we can at least make sure all the files are there
// this could easily be solved by adding an `order` property to the page's frontmatter
// https://github.com/ProjectEvergreen/greenwood/pull/1308#issuecomment-3368603613
it("should have the expected link content from all pages in the collection", function () {
expect(linkItems[0].getAttribute("href")).to.equal("/blog/");
expect(linkItems[0].getAttribute("title")).to.equal("Blog");
expect(linkItems[0].textContent).to.equal("Blog");
const blogLink = Array.from(linkItems).find(
(link) => link.getAttribute("href") === "/blog/",
);
const tocLink = Array.from(linkItems).find(
(link) => link.getAttribute("href") === "/toc/",
);

expect(linkItems[1].getAttribute("href")).to.equal("/toc/");
expect(linkItems[1].getAttribute("title")).to.equal("Table of Contents");
expect(linkItems[1].textContent).to.equal("Table of Contents");
expect(blogLink.getAttribute("title")).to.equal("Blog");
expect(blogLink.textContent).to.equal("Blog");

expect(tocLink.getAttribute("title")).to.equal("Table of Contents");
expect(tocLink.textContent).to.equal("Table of Contents");
});

it("should have the expected inline active frontmatter collection data", function () {
const collection = JSON.parse(
dom.window.document.querySelector("body span#footer").textContent,
);
const blogItem = collection.find((page) => page.route === "/blog/");
const tocItem = collection.find((page) => page.route === "/toc/");

expect(collection[0].route).to.equal("/blog/");
expect(collection[0].title).to.equal("Blog");
expect(collection[0].label).to.equal(collection[0].title);
expect(collection[0].id).to.equal("blog-index");
expect(blogItem.title).to.equal("Blog");
expect(blogItem.label).to.equal("Blog");
expect(blogItem.id).to.equal("blog-index");

expect(collection[1].route).to.equal("/toc/");
expect(collection[1].title).to.equal("Table of Contents");
expect(collection[1].label).to.equal(collection[1].title);
expect(collection[1].id).to.equal("toc");
expect(tocItem.title).to.equal("Table of Contents");
expect(tocItem.label).to.equal("Table of Contents");
expect(tocItem.id).to.equal("toc");
});
});
});
Expand All @@ -212,14 +220,22 @@ describe("Build Greenwood With: ", function () {
expect(postLinks.length).to.equal(2);
});

// we _technically_ can't assume the order of pages but we can at least make sure all the files are there
// this could easily be solved by adding an `order` property to the page's frontmatter
// https://github.com/ProjectEvergreen/greenwood/pull/1308#issuecomment-3368603613
it("should have the expected link content from all pages in the collection", function () {
expect(postLinks[0].getAttribute("href")).to.equal("/blog/first-post/");
expect(postLinks[0].getAttribute("title")).to.equal("First Post");
expect(postLinks[0].textContent).to.equal("First Post");
const firstPostLink = Array.from(postLinks).find(
(link) => link.getAttribute("href") === "/blog/first-post/",
);
const secondPostLink = Array.from(postLinks).find(
(link) => link.getAttribute("href") === "/blog/second-post/",
);

expect(firstPostLink.getAttribute("title")).to.equal("First Post");
expect(firstPostLink.textContent).to.equal("First Post");

expect(postLinks[1].getAttribute("href")).to.equal("/blog/second-post/");
expect(postLinks[1].getAttribute("title")).to.equal("Second Post");
expect(postLinks[1].textContent).to.equal("Second Post");
expect(secondPostLink.getAttribute("title")).to.equal("Second Post");
expect(secondPostLink.textContent).to.equal("Second Post");
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe("Build Greenwood With: ", function () {

before(async function () {
const headerScripts = await Array.fromAsync(
fs.glob("header.*.js", { cwd: new URL("./public/", import.meta.url) }),
fs.glob("header.*.js", { cwd: new URL("./public/", import.meta.url).pathname }),
);

headerContents = await fs.readFile(
Expand Down Expand Up @@ -87,7 +87,7 @@ describe("Build Greenwood With: ", function () {
before(async function () {
assets = (
await Array.fromAsync(
fs.glob("**", { cwd: new URL("./public/assets/", import.meta.url) }),
fs.glob("**", { cwd: new URL("./public/assets/", import.meta.url).pathname }),
)
).filter((assets) => assets.indexOf(".") > 0);
});
Expand Down
Loading
Loading