Skip to content

Commit

Permalink
Merge pull request #439 from jsenv/small_fixes
Browse files Browse the repository at this point in the history
take screenshot for syntax error autoreload
  • Loading branch information
dmail authored Nov 13, 2024
2 parents 3acf02f + e09f926 commit c9eb8b0
Show file tree
Hide file tree
Showing 28 changed files with 188 additions and 86 deletions.
28 changes: 15 additions & 13 deletions dist/jsenv_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -4851,7 +4851,7 @@ const writeHead = (
if (statusText === undefined) {
statusText = statusTextFromStatus(status);
} else {
statusText = statusText.replace(/\\n/g, "\n");
statusText = statusText.replace(/\n/g, "");
}
if (responseIsServerHttp2Stream) {
nodeHeaders = {
Expand Down Expand Up @@ -11530,7 +11530,9 @@ const assertAndNormalizeReturnValue = (hook, returnValue, info) => {
if (!returnValueAssertion.appliesTo.includes(hook.name)) {
continue;
}
const assertionResult = returnValueAssertion.assertion(returnValue, info);
const assertionResult = returnValueAssertion.assertion(returnValue, info, {
hook,
});
if (assertionResult !== undefined) {
// normalization
returnValue = assertionResult;
Expand All @@ -11544,15 +11546,15 @@ const returnValueAssertions = [
{
name: "url_assertion",
appliesTo: ["resolveReference", "redirectReference"],
assertion: (valueReturned) => {
assertion: (valueReturned, urlInfo, { hook }) => {
if (valueReturned instanceof URL) {
return valueReturned.href;
}
if (typeof valueReturned === "string") {
return undefined;
}
throw new Error(
`Unexpected value returned by plugin: it must be a string; got ${valueReturned}`,
`Unexpected value returned by "${hook.plugin.name}" plugin: it must be a string; got ${valueReturned}`,
);
},
},
Expand All @@ -11564,7 +11566,7 @@ const returnValueAssertions = [
"finalizeUrlContent",
"optimizeUrlContent",
],
assertion: (valueReturned, urlInfo) => {
assertion: (valueReturned, urlInfo, { hook }) => {
if (typeof valueReturned === "string" || Buffer.isBuffer(valueReturned)) {
return { content: valueReturned };
}
Expand All @@ -11575,13 +11577,13 @@ const returnValueAssertions = [
}
if (typeof content !== "string" && !Buffer.isBuffer(content) && !body) {
throw new Error(
`Unexpected "content" returned by plugin: it must be a string or a buffer; got ${content}`,
`Unexpected "content" returned by "${hook.plugin.name}" ${hook.name} hook: it must be a string or a buffer; got ${content}`,
);
}
return undefined;
}
throw new Error(
`Unexpected value returned by plugin: it must be a string, a buffer or an object; got ${valueReturned}`,
`Unexpected value returned by "${hook.plugin.name}" ${hook.name} hook: it must be a string, a buffer or an object; got ${valueReturned}`,
);
},
},
Expand Down Expand Up @@ -19908,13 +19910,13 @@ const injectImportMetaHot = (urlInfo, importMetaHotClientFileUrl) => {
expectedType: "js_module",
specifier: importMetaHotClientFileUrl,
});
const magicSource = createMagicSource(urlInfo.content);
magicSource.prepend(
`import { createImportMetaHot } from ${importMetaHotClientFileReference.generatedSpecifier};
let content = urlInfo.content;
let prelude = `import { createImportMetaHot } from ${importMetaHotClientFileReference.generatedSpecifier};
import.meta.hot = createImportMetaHot(import.meta.url);
`,
);
return magicSource.toContentAndSourcemap();
`;
return {
content: `${prelude.replace(/\n/g, "")}${content}`,
};
};

const jsenvPluginAutoreloadClient = () => {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/core",
"version": "39.5.21",
"version": "39.5.23",
"description": "Tool to develop, test and build js projects",
"license": "MIT",
"author": {
Expand Down Expand Up @@ -78,10 +78,10 @@
"@jsenv/node-esm-resolution": "1.0.6",
"@jsenv/plugin-bundling": "2.7.16",
"@jsenv/plugin-minification": "1.5.10",
"@jsenv/plugin-supervisor": "1.5.26",
"@jsenv/plugin-supervisor": "1.5.27",
"@jsenv/plugin-transpilation": "1.4.84",
"@jsenv/runtime-compat": "1.3.1",
"@jsenv/server": "15.3.2",
"@jsenv/server": "15.3.3",
"@jsenv/sourcemap": "1.2.25",
"@jsenv/url-meta": "8.5.2",
"@jsenv/urls": "2.5.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/independent/fetch/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/fetch",
"version": "1.1.75",
"version": "1.1.76",
"description": "Unified url fetcher (http, http, file, data)",
"license": "MIT",
"author": {
Expand Down Expand Up @@ -33,7 +33,7 @@
],
"dependencies": {
"@jsenv/urls": "2.5.2",
"@jsenv/server": "15.3.2",
"@jsenv/server": "15.3.3",
"node-fetch": "3.3.2"
}
}
2 changes: 1 addition & 1 deletion packages/independent/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/server",
"version": "15.3.2",
"version": "15.3.3",
"description": "Write your Node.js server using pure functions",
"license": "MIT",
"author": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const writeHead = (
if (statusText === undefined) {
statusText = statusTextFromStatus(status);
} else {
statusText = statusText.replace(/\\n/g, "\n");
statusText = statusText.replace(/\n/g, "");
}
if (responseIsServerHttp2Stream) {
nodeHeaders = {
Expand Down
4 changes: 2 additions & 2 deletions packages/independent/snapshot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/snapshot",
"version": "2.11.18",
"version": "2.11.19",
"description": "Snapshot testing",
"license": "MIT",
"author": {
Expand Down Expand Up @@ -35,7 +35,7 @@
"@jsenv/exception": "1.1.3",
"@jsenv/humanize": "1.2.8",
"@jsenv/filesystem": "4.10.11",
"@jsenv/terminal-recorder": "1.4.16",
"@jsenv/terminal-recorder": "1.4.17",
"@jsenv/urls": "2.5.2",
"@jsenv/utils": "2.1.2",
"ansi-regex": "6.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/independent/terminal-recorder/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/terminal-recorder",
"version": "1.4.16",
"version": "1.4.17",
"description": "Record terminal output as .svg, .gif, .webm, .mp4",
"license": "MIT",
"repository": {
Expand Down Expand Up @@ -38,7 +38,7 @@
},
"dependencies": {
"@jsenv/humanize": "1.2.8",
"@jsenv/server": "15.3.2",
"@jsenv/server": "15.3.3",
"@playwright/browser-chromium": "1.48.2",
"ansi-regex": "6.1.0",
"he": "1.2.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/independent/workflow/github-check-run/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/github-check-run",
"version": "0.2.2",
"version": "0.2.3",
"description": "Interact with GitHub check rest API",
"license": "MIT",
"author": {
Expand Down Expand Up @@ -30,7 +30,7 @@
"/src/"
],
"dependencies": {
"@jsenv/fetch": "1.1.75",
"@jsenv/fetch": "1.1.76",
"@jsenv/humanize": "1.2.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,38 @@ isBrowser ? () => {
throw new Error('`process.cwd()` only works in Node.js, not the browser.');
} : process$1.cwd;

// normalize url search params:
// Using URLSearchParams to alter the url search params
// can result into "file:///file.css?css_module"
// becoming "file:///file.css?css_module="
// we want to get rid of the "=" and consider it's the same url
const normalizeUrl = url => {
if (url.includes("?")) {
// disable on data urls (would mess up base64 encoding)
if (url.startsWith("data:")) {
return url;
}
return url.replace(/[=](?=&|$)/g, "");
}
return url;
};
const injectQueryParams = (url, params) => {
const urlObject = new URL(url);
const {
searchParams
} = urlObject;
Object.keys(params).forEach(key => {
const value = params[key];
if (value === undefined) {
searchParams.delete(key);
} else {
searchParams.set(key, value);
}
});
const urlWithParams = urlObject.href;
return normalizeUrl(urlWithParams);
};

const getCommonPathname = (pathname, otherPathname) => {
if (pathname === otherPathname) {
return pathname;
Expand Down Expand Up @@ -1199,7 +1231,9 @@ const jsenvPluginSupervisor = ({
const resolveUrlSite = urlWithLineAndColumn => {
const inlineUrlMatch = urlWithLineAndColumn.match(/@L([0-9]+)C([0-9]+)-L([0-9]+)C([0-9]+)\.\w+(:([0-9]+):([0-9]+))?$/);
if (inlineUrlMatch) {
const htmlUrl = urlWithLineAndColumn.slice(0, inlineUrlMatch.index);
const htmlUrl = injectQueryParams(urlWithLineAndColumn.slice(0, inlineUrlMatch.index), {
hot: undefined
});
const tagLineStart = parseInt(inlineUrlMatch[1]);
const tagColumnStart = parseInt(inlineUrlMatch[2]);
// const tagLineEnd = parseInt(inlineUrlMatch[3]);
Expand All @@ -1220,7 +1254,9 @@ const jsenvPluginSupervisor = ({
if (!match) {
return null;
}
const file = urlWithLineAndColumn.slice(0, match.index);
const file = injectQueryParams(urlWithLineAndColumn.slice(0, match.index), {
hot: undefined
});
let line = parseInt(match[1]);
let column = parseInt(match[2]);
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/plugin-supervisor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/plugin-supervisor",
"version": "1.5.26",
"version": "1.5.27",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { generateContentFrame } from "@jsenv/humanize";
import { getOriginalPosition } from "@jsenv/sourcemap";
import { injectQueryParams } from "@jsenv/urls";
import { createRequire } from "node:module";
import { fileURLToPath } from "node:url";
import {
Expand All @@ -24,7 +25,10 @@ export const jsenvPluginSupervisor = ({
/@L([0-9]+)C([0-9]+)-L([0-9]+)C([0-9]+)\.\w+(:([0-9]+):([0-9]+))?$/,
);
if (inlineUrlMatch) {
const htmlUrl = urlWithLineAndColumn.slice(0, inlineUrlMatch.index);
const htmlUrl = injectQueryParams(
urlWithLineAndColumn.slice(0, inlineUrlMatch.index),
{ hot: undefined },
);
const tagLineStart = parseInt(inlineUrlMatch[1]);
const tagColumnStart = parseInt(inlineUrlMatch[2]);
// const tagLineEnd = parseInt(inlineUrlMatch[3]);
Expand Down Expand Up @@ -52,7 +56,9 @@ export const jsenvPluginSupervisor = ({
if (!match) {
return null;
}
const file = urlWithLineAndColumn.slice(0, match.index);
const file = injectQueryParams(urlWithLineAndColumn.slice(0, match.index), {
hot: undefined,
});
let line = parseInt(match[1]);
let column = parseInt(match[2]);
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/related/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/cli",
"version": "0.2.5",
"version": "0.2.7",
"description": "Command Line Interface for jsenv",
"license": "MIT",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions packages/related/cli/template-node-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
},
"devDependencies": {
"@jsenv/assert": "4.4.2",
"@jsenv/core": "39.5.21",
"@jsenv/core": "39.5.23",
"@jsenv/eslint-config-relax": "1.2.12",
"@jsenv/test": "3.5.24",
"@jsenv/test": "3.5.25",
"eslint": "9.14.0",
"prettier": "3.3.3"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/related/cli/template-web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
"@babel/plugin-syntax-import-attributes": "7.26.0",
"@jsenv/custom-elements-redefine": "0.0.1",
"@jsenv/assert": "4.4.2",
"@jsenv/core": "39.5.21",
"@jsenv/core": "39.5.23",
"@jsenv/plugin-bundling": "2.7.16",
"@jsenv/plugin-minification": "1.5.10",
"@jsenv/eslint-config-relax": "1.2.12",
"@jsenv/test": "3.5.24",
"@jsenv/test": "3.5.25",
"eslint": "9.14.0",
"open": "10.1.0",
"@playwright/browser-chromium": "1.48.2",
Expand Down
6 changes: 3 additions & 3 deletions packages/related/cli/template-web-preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
"@babel/plugin-syntax-import-attributes": "7.26.0",
"@babel/plugin-transform-react-jsx": "7.25.9",
"@jsenv/assert": "4.4.2",
"@jsenv/core": "39.5.21",
"@jsenv/plugin-preact": "1.6.25",
"@jsenv/core": "39.5.23",
"@jsenv/plugin-preact": "1.6.26",
"@jsenv/plugin-bundling": "2.7.16",
"@jsenv/plugin-minification": "1.5.10",
"@jsenv/eslint-config-relax": "1.2.12",
"@jsenv/test": "3.5.24",
"@jsenv/test": "3.5.25",
"eslint": "9.14.0",
"open": "10.1.0",
"@playwright/browser-chromium": "1.48.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/related/cli/template-web-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
"@babel/plugin-syntax-import-attributes": "7.26.0",
"@babel/plugin-transform-react-jsx": "7.25.9",
"@jsenv/assert": "4.4.2",
"@jsenv/core": "39.5.21",
"@jsenv/core": "39.5.23",
"@jsenv/plugin-react": "1.5.44",
"@jsenv/plugin-bundling": "2.7.16",
"@jsenv/plugin-minification": "1.5.10",
"@jsenv/eslint-config-relax": "1.2.12",
"@jsenv/test": "3.5.24",
"@jsenv/test": "3.5.25",
"eslint": "9.14.0",
"open": "10.1.0",
"@playwright/browser-chromium": "1.48.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/related/cli/template-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"devDependencies": {
"@babel/plugin-syntax-import-attributes": "7.26.0",
"@jsenv/assert": "4.4.2",
"@jsenv/core": "39.5.21",
"@jsenv/core": "39.5.23",
"@jsenv/eslint-config-relax": "1.2.12",
"@jsenv/plugin-bundling": "2.7.16",
"@jsenv/plugin-minification": "1.5.10",
"@jsenv/test": "3.5.24",
"@jsenv/test": "3.5.25",
"eslint": "9.14.0",
"open": "10.1.0",
"@playwright/browser-chromium": "1.48.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/related/plugin-preact/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/plugin-preact",
"version": "1.6.25",
"version": "1.6.26",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
Loading

0 comments on commit c9eb8b0

Please sign in to comment.