@jsenv/core 41.0.0 → 41.0.2

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.
@@ -7677,10 +7677,15 @@ const jsenvPluginImportMetaCss = () => {
7677
7677
  return null;
7678
7678
  }
7679
7679
  if (urlInfo.context.build) {
7680
- const rootDirectoryUrl = urlInfo.context.rootDirectoryUrl;
7681
- const relativeUrl = urlInfo.originalUrl.slice(
7682
- rootDirectoryUrl.length - 1,
7680
+ const packageName = urlInfo.packageName;
7681
+ const packageDirectoryUrl =
7682
+ urlInfo.packageDirectoryUrl || urlInfo.context.rootDirectoryUrl;
7683
+ const relativePathInPackage = urlInfo.originalUrl.slice(
7684
+ packageDirectoryUrl.length - 1,
7683
7685
  );
7686
+ const relativeUrl = packageName
7687
+ ? `${packageName}${relativePathInPackage}`
7688
+ : relativePathInPackage;
7684
7689
  const { code } = await applyBabelPlugins({
7685
7690
  babelPlugins: [
7686
7691
  [babelPluginRewriteImportMetaCssAssignment, { relativeUrl }],
@@ -32,7 +32,7 @@ import "node:url";
32
32
  */
33
33
  const startBuildServer = async ({
34
34
  buildDirectoryUrl,
35
- buildMainFilePath = "index.html",
35
+ buildDirectoryMainFileRelativeUrl = "index.html",
36
36
  port = 9779,
37
37
  routes,
38
38
  serverPlugins = [],
@@ -62,26 +62,35 @@ const startBuildServer = async ({
62
62
  "buildDirectoryUrl",
63
63
  );
64
64
 
65
- if (buildMainFilePath) {
66
- if (typeof buildMainFilePath !== "string") {
65
+ if (buildDirectoryMainFileRelativeUrl) {
66
+ if (typeof buildDirectoryMainFileRelativeUrl !== "string") {
67
67
  throw new TypeError(
68
- `buildMainFilePath must be a string, got ${buildMainFilePath}`,
68
+ `buildDirectoryMainFileRelativeUrl must be a string, got ${buildDirectoryMainFileRelativeUrl}`,
69
69
  );
70
70
  }
71
- if (buildMainFilePath[0] === "/") {
72
- buildMainFilePath = buildMainFilePath.slice(1);
71
+ if (buildDirectoryMainFileRelativeUrl[0] === "/") {
72
+ buildDirectoryMainFileRelativeUrl =
73
+ buildDirectoryMainFileRelativeUrl.slice(1);
73
74
  } else {
74
- const buildMainFileUrl = new URL(buildMainFilePath, buildDirectoryUrl)
75
- .href;
75
+ const buildMainFileUrl = new URL(
76
+ buildDirectoryMainFileRelativeUrl,
77
+ buildDirectoryUrl,
78
+ ).href;
76
79
  if (!buildMainFileUrl.startsWith(buildDirectoryUrl)) {
77
80
  throw new Error(
78
- `buildMainFilePath must be relative, got ${buildMainFilePath}`,
81
+ `buildDirectoryMainFileRelativeUrl must be relative, got ${buildDirectoryMainFileRelativeUrl}`,
79
82
  );
80
83
  }
81
- buildMainFilePath = buildMainFileUrl.slice(buildDirectoryUrl.length);
84
+ buildDirectoryMainFileRelativeUrl = buildMainFileUrl.slice(
85
+ buildDirectoryUrl.length,
86
+ );
82
87
  }
83
- if (!existsSync(new URL(buildMainFilePath, buildDirectoryUrl))) {
84
- buildMainFilePath = null;
88
+ if (
89
+ !existsSync(
90
+ new URL(buildDirectoryMainFileRelativeUrl, buildDirectoryUrl),
91
+ )
92
+ ) {
93
+ buildDirectoryMainFileRelativeUrl = null;
85
94
  }
86
95
  }
87
96
  }
@@ -130,8 +139,9 @@ const startBuildServer = async ({
130
139
  }),
131
140
  ...serverPlugins,
132
141
  serverPluginStaticFiles({
142
+ serverRelativeUrl: "/",
133
143
  directoryUrl: buildDirectoryUrl,
134
- mainFilePath: buildMainFilePath,
144
+ directoryMainFileRelativeUrl: buildDirectoryMainFileRelativeUrl,
135
145
  }),
136
146
  serverPluginErrorHandler({
137
147
  sendErrorDetails: false,
@@ -7718,10 +7718,15 @@ const jsenvPluginImportMetaCss = () => {
7718
7718
  return null;
7719
7719
  }
7720
7720
  if (urlInfo.context.build) {
7721
- const rootDirectoryUrl = urlInfo.context.rootDirectoryUrl;
7722
- const relativeUrl = urlInfo.originalUrl.slice(
7723
- rootDirectoryUrl.length - 1,
7721
+ const packageName = urlInfo.packageName;
7722
+ const packageDirectoryUrl =
7723
+ urlInfo.packageDirectoryUrl || urlInfo.context.rootDirectoryUrl;
7724
+ const relativePathInPackage = urlInfo.originalUrl.slice(
7725
+ packageDirectoryUrl.length - 1,
7724
7726
  );
7727
+ const relativeUrl = packageName
7728
+ ? `${packageName}${relativePathInPackage}`
7729
+ : relativePathInPackage;
7725
7730
  const { code } = await applyBabelPlugins({
7726
7731
  babelPlugins: [
7727
7732
  [babelPluginRewriteImportMetaCssAssignment, { relativeUrl }],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "41.0.0",
3
+ "version": "41.0.2",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "repository": {
6
6
  "type": "git",
@@ -81,7 +81,7 @@
81
81
  "@jsenv/plugin-minification": "1.7.3",
82
82
  "@jsenv/plugin-supervisor": "1.7.15",
83
83
  "@jsenv/plugin-transpilation": "1.5.70",
84
- "@jsenv/server": "17.0.0",
84
+ "@jsenv/server": "17.0.1",
85
85
  "@jsenv/sourcemap": "1.3.17",
86
86
  "react-table": "7.8.0"
87
87
  },
@@ -33,7 +33,7 @@ import { existsSync } from "node:fs";
33
33
  */
34
34
  export const startBuildServer = async ({
35
35
  buildDirectoryUrl,
36
- buildMainFilePath = "index.html",
36
+ buildDirectoryMainFileRelativeUrl = "index.html",
37
37
  port = 9779,
38
38
  routes,
39
39
  serverPlugins = [],
@@ -63,26 +63,35 @@ export const startBuildServer = async ({
63
63
  "buildDirectoryUrl",
64
64
  );
65
65
 
66
- if (buildMainFilePath) {
67
- if (typeof buildMainFilePath !== "string") {
66
+ if (buildDirectoryMainFileRelativeUrl) {
67
+ if (typeof buildDirectoryMainFileRelativeUrl !== "string") {
68
68
  throw new TypeError(
69
- `buildMainFilePath must be a string, got ${buildMainFilePath}`,
69
+ `buildDirectoryMainFileRelativeUrl must be a string, got ${buildDirectoryMainFileRelativeUrl}`,
70
70
  );
71
71
  }
72
- if (buildMainFilePath[0] === "/") {
73
- buildMainFilePath = buildMainFilePath.slice(1);
72
+ if (buildDirectoryMainFileRelativeUrl[0] === "/") {
73
+ buildDirectoryMainFileRelativeUrl =
74
+ buildDirectoryMainFileRelativeUrl.slice(1);
74
75
  } else {
75
- const buildMainFileUrl = new URL(buildMainFilePath, buildDirectoryUrl)
76
- .href;
76
+ const buildMainFileUrl = new URL(
77
+ buildDirectoryMainFileRelativeUrl,
78
+ buildDirectoryUrl,
79
+ ).href;
77
80
  if (!buildMainFileUrl.startsWith(buildDirectoryUrl)) {
78
81
  throw new Error(
79
- `buildMainFilePath must be relative, got ${buildMainFilePath}`,
82
+ `buildDirectoryMainFileRelativeUrl must be relative, got ${buildDirectoryMainFileRelativeUrl}`,
80
83
  );
81
84
  }
82
- buildMainFilePath = buildMainFileUrl.slice(buildDirectoryUrl.length);
85
+ buildDirectoryMainFileRelativeUrl = buildMainFileUrl.slice(
86
+ buildDirectoryUrl.length,
87
+ );
83
88
  }
84
- if (!existsSync(new URL(buildMainFilePath, buildDirectoryUrl))) {
85
- buildMainFilePath = null;
89
+ if (
90
+ !existsSync(
91
+ new URL(buildDirectoryMainFileRelativeUrl, buildDirectoryUrl),
92
+ )
93
+ ) {
94
+ buildDirectoryMainFileRelativeUrl = null;
86
95
  }
87
96
  }
88
97
  }
@@ -132,8 +141,9 @@ export const startBuildServer = async ({
132
141
  }),
133
142
  ...serverPlugins,
134
143
  serverPluginStaticFiles({
144
+ serverRelativeUrl: "/",
135
145
  directoryUrl: buildDirectoryUrl,
136
- mainFilePath: buildMainFilePath,
146
+ directoryMainFileRelativeUrl: buildDirectoryMainFileRelativeUrl,
137
147
  }),
138
148
  serverPluginErrorHandler({
139
149
  sendErrorDetails: false,
@@ -51,10 +51,15 @@ export const jsenvPluginImportMetaCss = () => {
51
51
  return null;
52
52
  }
53
53
  if (urlInfo.context.build) {
54
- const rootDirectoryUrl = urlInfo.context.rootDirectoryUrl;
55
- const relativeUrl = urlInfo.originalUrl.slice(
56
- rootDirectoryUrl.length - 1,
54
+ const packageName = urlInfo.packageName;
55
+ const packageDirectoryUrl =
56
+ urlInfo.packageDirectoryUrl || urlInfo.context.rootDirectoryUrl;
57
+ const relativePathInPackage = urlInfo.originalUrl.slice(
58
+ packageDirectoryUrl.length - 1,
57
59
  );
60
+ const relativeUrl = packageName
61
+ ? `${packageName}${relativePathInPackage}`
62
+ : relativePathInPackage;
58
63
  const { code } = await applyBabelPlugins({
59
64
  babelPlugins: [
60
65
  [babelPluginRewriteImportMetaCssAssignment, { relativeUrl }],