Skip to content

Commit

Permalink
Merge pull request #438 from jsenv/bare_specifier_improve
Browse files Browse the repository at this point in the history
Bare specifier improve
  • Loading branch information
dmail authored Nov 6, 2024
2 parents 74db996 + 6423eae commit 4746e40
Show file tree
Hide file tree
Showing 42 changed files with 266 additions and 66 deletions.
10 changes: 9 additions & 1 deletion dist/jsenv_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -11591,6 +11591,7 @@ const createResolveUrlError = ({
error,
}) => {
const createFailedToResolveUrlError = ({
name = "RESOLVE_URL_ERROR",
code = error.code || "RESOLVE_URL_ERROR",
reason,
...details
Expand All @@ -11609,10 +11610,11 @@ ${reason}`,
);
defineNonEnumerableProperties(resolveError, {
isJsenvCookingError: true,
name: "RESOLVE_URL_ERROR",
name,
code,
reason,
asResponse: error.asResponse,
trace: error.trace || reference.trace,
});
return resolveError;
};
Expand All @@ -11621,6 +11623,12 @@ ${reason}`,
reason: `no plugin has handled the specifier during "resolveUrl" hook`,
});
}
if (error.code === "MODULE_NOT_FOUND") {
const bareSpecifierError = createFailedToResolveUrlError({
reason: `"${reference.specifier}" is a bare specifier but cannot be remapped to a package`,
});
return bareSpecifierError;
}
if (error.code === "DIRECTORY_REFERENCE_NOT_ALLOWED") {
error.message = createDetailedMessage$1(error.message, {
"reference trace": reference.trace.message,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/core",
"version": "39.5.17",
"version": "39.5.18",
"description": "Tool to develop, test and build js projects",
"license": "MIT",
"author": {
Expand Down Expand Up @@ -78,7 +78,7 @@
"@jsenv/node-esm-resolution": "1.0.6",
"@jsenv/plugin-bundling": "2.7.16",
"@jsenv/plugin-minification": "1.5.10",
"@jsenv/plugin-supervisor": "1.5.23",
"@jsenv/plugin-supervisor": "1.5.24",
"@jsenv/plugin-transpilation": "1.4.83",
"@jsenv/runtime-compat": "1.3.1",
"@jsenv/server": "15.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/independent/assert/dist/jsenv_assert_browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2664,7 +2664,7 @@ const createAssert = ({
comparison.hasAnyDiff = overall.any.size > 0;
comparison.done = true;
const updateNodeDiffType = (node, otherNode) => {
if (node.diffType !== "") {
if (node.diffType !== "" && !allowRecompare) {
return;
}
let diffType = "";
Expand Down
2 changes: 1 addition & 1 deletion packages/independent/assert/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsenv/assert",
"version": "4.4.1",
"version": "4.4.2",
"description": "One assertion to test everything",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/independent/assert/src/assert_scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ export const createAssert = ({
comparison.done = true;

const updateNodeDiffType = (node, otherNode) => {
if (node.diffType !== "") {
if (node.diffType !== "" && !allowRecompare) {
return;
}
let diffType = "";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [3500 is between 3000 and 5000](../../assert_between.test.js#L37)
# [3500 is between 3000 and 5000](../../assert_between.test.js#L47)

```js
assert({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# [500 not between 100, 200](../../assert_between.test.js#L37)

```js
assert({
actual: {
duration: 500,
},
expect: {
duration: assert.between(100, 200),
},
});
```

![img](throw.svg)

<details>
<summary>see without style</summary>

```console
AssertionError: actual and expect are different

actual: {
duration: 500,
}
expect: {
duration: assert.between(100, 200),
}
```

</details>


---

<sub>
Generated by <a href="https://github.com/jsenv/core/tree/main/packages/independent/snapshot">@jsenv/snapshot</a>
</sub>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [below or equals when removed](below_or_equals_when_removed/below_or_equals_when_removed.md)
- [below or equals ok](below_or_equals_ok/below_or_equals_ok.md)
- [50 is too small](50_is_too_small/50_is_too_small.md)
- [500 not between 100, 200](500_not_between_100__200/500_not_between_100__200.md)
- [3500 is between 3000 and 5000](3500_is_between_3000_and_5000/3500_is_between_3000_and_5000.md)

---
Expand Down
10 changes: 10 additions & 0 deletions packages/independent/assert/tests/assert_between.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ await snapshotAssertTests(import.meta.url, ({ test }) => {
expect: assert.between(100, 200),
});
});
test("500 not between 100, 200", () => {
assert({
actual: {
duration: 500,
},
expect: {
duration: assert.between(100, 200),
},
});
});
test("3500 is between 3000 and 5000", () => {
assert({
actual: {
Expand Down
1 change: 1 addition & 0 deletions packages/independent/md-up/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@jsenv/md-up",
"version": "0.0.1",
"license": "MIT",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/jsenv/core",
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.15",
"version": "2.11.16",
"description": "Snapshot testing",
"license": "MIT",
"author": {
Expand Down Expand Up @@ -30,7 +30,7 @@
"/src/"
],
"dependencies": {
"@jsenv/assert": "4.4.1",
"@jsenv/assert": "4.4.2",
"@jsenv/ast": "6.3.4",
"@jsenv/exception": "1.1.3",
"@jsenv/humanize": "1.2.8",
Expand Down
24 changes: 14 additions & 10 deletions packages/internal/plugin-supervisor/dist/js/supervisor.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,19 +737,19 @@ window.__supervisor__ = (() => {
message,
stackTrace
}) => {
let stack = "";
const parts = [];
if (codeFrame) {
stack += "".concat(codeFrame, "\n");
parts.push(codeFrame);
}
if (name && message) {
stack += "".concat(name, ": ").concat(message);
parts.push("".concat(name, ": ").concat(message));
} else if (message) {
stack += message;
parts.push(message);
}
if (stackTrace) {
stack += "\n".concat(stackTrace);
parts.push(stackTrace);
}
return stack;
return parts.join("\n");
};
const stringifyUrlSite = ({
url,
Expand Down Expand Up @@ -972,13 +972,14 @@ window.__supervisor__ = (() => {
const {
trace = {}
} = cause;
const dataToRender = cause.code === "MODULE_NOT_FOUND" ? cause : exception;
root.querySelector(".text").innerHTML = stringifyStack({
codeFrame: trace.codeFrame ? generateClickableText(trace.codeFrame) : "",
name: exception.name,
message: exception.message ? generateClickableText(exception.message) : "",
stackTrace: exception.stackTrace ? generateClickableText(exception.stackTrace) : ""
name: dataToRender.name,
message: cause.code === "MODULE_NOT_FOUND" ? generateClickableText(dataToRender.reason) : dataToRender.message ? generateClickableText(dataToRender.message) : "",
stackTrace: dataToRender.stackTrace ? generateClickableText(dataToRender.stackTrace) : ""
});
if (cause) {
if (cause && dataToRender === exception) {
const causeText = stringifyStack({
name: getErrorName(cause),
message: cause.reason ? generateClickableText(cause.reason) : cause.stack ? generateClickableText(cause.stack) : ""
Expand Down Expand Up @@ -1237,6 +1238,9 @@ window.__supervisor__ = (() => {
});
};
const getErrorName = value => {
if (value.code === "MODULE_NOT_FOUND") {
return "TypeError";
}
const {
constructor
} = value;
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.23",
"version": "1.5.24",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
35 changes: 21 additions & 14 deletions packages/internal/plugin-supervisor/src/client/supervisor.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,19 +707,19 @@ window.__supervisor__ = (() => {
};

const stringifyStack = ({ codeFrame, name, message, stackTrace }) => {
let stack = "";
const parts = [];
if (codeFrame) {
stack += `${codeFrame}\n`;
parts.push(codeFrame);
}
if (name && message) {
stack += `${name}: ${message}`;
parts.push(`${name}: ${message}`);
} else if (message) {
stack += message;
parts.push(message);
}
if (stackTrace) {
stack += `\n${stackTrace}`;
parts.push(stackTrace);
}
return stack;
return parts.join("\n");
};

const stringifyUrlSite = ({ url, line, column }) => {
Expand Down Expand Up @@ -971,20 +971,24 @@ window.__supervisor__ = (() => {
const renderException = () => {
const { cause = {} } = exception;
const { trace = {} } = cause;

const dataToRender =
cause.code === "MODULE_NOT_FOUND" ? cause : exception;
root.querySelector(".text").innerHTML = stringifyStack({
codeFrame: trace.codeFrame
? generateClickableText(trace.codeFrame)
: "",
name: exception.name,
message: exception.message
? generateClickableText(exception.message)
: "",
stackTrace: exception.stackTrace
? generateClickableText(exception.stackTrace)
name: dataToRender.name,
message:
cause.code === "MODULE_NOT_FOUND"
? generateClickableText(dataToRender.reason)
: dataToRender.message
? generateClickableText(dataToRender.message)
: "",
stackTrace: dataToRender.stackTrace
? generateClickableText(dataToRender.stackTrace)
: "",
});
if (cause) {
if (cause && dataToRender === exception) {
const causeText = stringifyStack({
name: getErrorName(cause),
message: cause.reason
Expand Down Expand Up @@ -1329,6 +1333,9 @@ window.__supervisor__ = (() => {
};

const getErrorName = (value) => {
if (value.code === "MODULE_NOT_FOUND") {
return "TypeError";
}
const { constructor } = value;
if (constructor) {
if (constructor.name !== "Object") {
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.1.60",
"version": "0.1.62",
"description": "Command Line Interface for jsenv",
"license": "MIT",
"repository": {
Expand Down
6 changes: 3 additions & 3 deletions packages/related/cli/template-node-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"test:coverage": "npm run test -- --coverage"
},
"devDependencies": {
"@jsenv/assert": "4.4.1",
"@jsenv/core": "39.5.17",
"@jsenv/assert": "4.4.2",
"@jsenv/core": "39.5.18",
"@jsenv/eslint-config-relax": "1.2.12",
"@jsenv/test": "3.5.20",
"@jsenv/test": "3.5.21",
"eslint": "9.14.0",
"prettier": "3.3.3"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/related/cli/template-web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"devDependencies": {
"@babel/plugin-syntax-import-assertions": "7.26.0",
"@jsenv/custom-elements-redefine": "0.0.1",
"@jsenv/assert": "4.4.1",
"@jsenv/core": "39.5.17",
"@jsenv/assert": "4.4.2",
"@jsenv/core": "39.5.18",
"@jsenv/plugin-bundling": "2.7.16",
"@jsenv/plugin-minification": "1.5.10",
"@jsenv/eslint-config-relax": "1.2.12",
"@jsenv/test": "3.5.20",
"@jsenv/test": "3.5.21",
"eslint": "9.14.0",
"open": "10.1.0",
"@playwright/browser-chromium": "1.48.2",
Expand Down
Loading

0 comments on commit 4746e40

Please sign in to comment.