Skip to content

Commit 5f9ef61

Browse files
committed
work
1 parent bd6b491 commit 5f9ef61

64 files changed

Lines changed: 1997 additions & 1696 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

dist/build/build.js

Lines changed: 121 additions & 41 deletions
Large diffs are not rendered by default.

dist/build/jsenv_core_packages.js

Lines changed: 3 additions & 187 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { extname } from "node:path";
33
import { readFileSync as readFileSync$1, existsSync, readdir, chmod, stat, lstat, chmodSync, statSync, lstatSync, promises, readdirSync, openSync, closeSync, unlinkSync, rmdirSync, mkdirSync, writeFileSync as writeFileSync$1, unlink, rmdir, watch, realpathSync } from "node:fs";
44
import crypto, { createHash } from "node:crypto";
55
import { pathToFileURL, fileURLToPath } from "node:url";
6-
import { cpus, totalmem, freemem } from "node:os";
7-
import { cpuUsage, memoryUsage } from "node:process";
6+
import { totalmem, freemem } from "node:os";
7+
import { memoryUsage } from "node:process";
88
import { stripVTControlCharacters } from "node:util";
99

1010
const createCallbackListNotifiedOnce = () => {
@@ -6548,174 +6548,6 @@ const getExtensionsToTry = (magicExtensions, importer) => {
65486548
return Array.from(extensionsSet.values());
65496549
};
65506550

6551-
const startMeasuringTotalCpuUsage = () => {
6552-
let previousCpuArray = cpus();
6553-
let previousMs = Date.now();
6554-
let previousCpuUsage = cpuUsage();
6555-
6556-
const overall = {
6557-
inactive: 100,
6558-
active: 0,
6559-
system: 0,
6560-
user: 0,
6561-
};
6562-
const thisProcess = {
6563-
active: 0,
6564-
system: 0,
6565-
user: 0,
6566-
};
6567-
const details = previousCpuArray.map(() => {
6568-
return {
6569-
inactive: 100,
6570-
active: 0,
6571-
system: 0,
6572-
user: 0,
6573-
};
6574-
});
6575-
6576-
const samples = [];
6577-
const interval = setInterval(() => {
6578-
let cpuArray = cpus();
6579-
const ms = Date.now();
6580-
const ellapsedMs = ms - previousMs;
6581-
const cpuUsageSampleArray = [];
6582-
let overallSystemMs = 0;
6583-
let overallUserMs = 0;
6584-
let overallInactiveMs = 0;
6585-
let overallActiveMs = 0;
6586-
let overallMsEllapsed = 0;
6587-
let index = 0;
6588-
for (const cpu of cpuArray) {
6589-
const previousCpuTimes = previousCpuArray[index].times;
6590-
const cpuTimes = cpu.times;
6591-
const systemMs = cpuTimes.sys - previousCpuTimes.sys;
6592-
const userMs = cpuTimes.user - previousCpuTimes.user;
6593-
const activeMs = systemMs + userMs;
6594-
const inactiveMs = ellapsedMs - activeMs;
6595-
const cpuUsageSample = {
6596-
inactive: inactiveMs / ellapsedMs,
6597-
active: activeMs / ellapsedMs,
6598-
system: systemMs / ellapsedMs,
6599-
user: userMs / ellapsedMs,
6600-
};
6601-
cpuUsageSampleArray.push(cpuUsageSample);
6602-
6603-
overallSystemMs += systemMs;
6604-
overallUserMs += userMs;
6605-
overallInactiveMs += inactiveMs;
6606-
overallActiveMs += activeMs;
6607-
overallMsEllapsed += ellapsedMs;
6608-
index++;
6609-
}
6610-
const overallUsageSample = {
6611-
inactive: overallInactiveMs / overallMsEllapsed,
6612-
active: overallActiveMs / overallMsEllapsed,
6613-
system: overallSystemMs / overallMsEllapsed,
6614-
user: overallUserMs / overallMsEllapsed,
6615-
};
6616-
previousCpuArray = cpuArray;
6617-
previousMs = ms;
6618-
6619-
const processCpuUsage = cpuUsage();
6620-
const thisProcessSystemMs = Math.round(
6621-
(processCpuUsage.system - previousCpuUsage.system) / 1000,
6622-
);
6623-
const thisProcessUserMs = Math.round(
6624-
(processCpuUsage.user - previousCpuUsage.user) / 1000,
6625-
);
6626-
previousCpuUsage = processCpuUsage;
6627-
6628-
const thisProcessActiveMs = thisProcessSystemMs + thisProcessUserMs;
6629-
const thisProcessInactiveMs = overallMsEllapsed - thisProcessActiveMs;
6630-
const thisProcessSample = {
6631-
inactive: thisProcessInactiveMs / overallMsEllapsed,
6632-
active: thisProcessActiveMs / overallMsEllapsed,
6633-
system: thisProcessSystemMs / overallMsEllapsed,
6634-
user: thisProcessUserMs / overallMsEllapsed,
6635-
};
6636-
samples.push({
6637-
cpuUsageSampleArray,
6638-
overallUsageSample,
6639-
thisProcessSample,
6640-
});
6641-
if (samples.length === 10) {
6642-
{
6643-
let index = 0;
6644-
for (const detail of details) {
6645-
let systemSum = 0;
6646-
let userSum = 0;
6647-
let inactiveSum = 0;
6648-
let activeSum = 0;
6649-
for (const sample of samples) {
6650-
const { cpuUsageSampleArray } = sample;
6651-
const cpuUsageSample = cpuUsageSampleArray[index];
6652-
inactiveSum += cpuUsageSample.inactive;
6653-
activeSum += cpuUsageSample.active;
6654-
systemSum += cpuUsageSample.system;
6655-
userSum += cpuUsageSample.user;
6656-
}
6657-
Object.assign(detail, {
6658-
inactive: inactiveSum / samples.length,
6659-
active: activeSum / samples.length,
6660-
system: systemSum / samples.length,
6661-
user: userSum / samples.length,
6662-
});
6663-
index++;
6664-
}
6665-
}
6666-
{
6667-
let overallSystemSum = 0;
6668-
let overallUserSum = 0;
6669-
let overallInactiveSum = 0;
6670-
let overallActiveSum = 0;
6671-
for (const sample of samples) {
6672-
const { overallUsageSample } = sample;
6673-
overallSystemSum += overallUsageSample.system;
6674-
overallUserSum += overallUsageSample.user;
6675-
overallInactiveSum += overallUsageSample.inactive;
6676-
overallActiveSum += overallUsageSample.active;
6677-
}
6678-
Object.assign(overall, {
6679-
inactive: overallInactiveSum / samples.length,
6680-
active: overallActiveSum / samples.length,
6681-
system: overallSystemSum / samples.length,
6682-
user: overallUserSum / samples.length,
6683-
});
6684-
}
6685-
{
6686-
let thisProcessSystemSum = 0;
6687-
let thisProcessUserSum = 0;
6688-
let thisProcessInactiveSum = 0;
6689-
let thisProcessActiveSum = 0;
6690-
for (const sample of samples) {
6691-
const { thisProcessSample } = sample;
6692-
thisProcessSystemSum += thisProcessSample.system;
6693-
thisProcessUserSum += thisProcessSample.user;
6694-
thisProcessInactiveSum += thisProcessSample.inactive;
6695-
thisProcessActiveSum += thisProcessSample.active;
6696-
}
6697-
Object.assign(thisProcess, {
6698-
inactive: thisProcessInactiveSum / samples.length,
6699-
active: thisProcessActiveSum / samples.length,
6700-
system: thisProcessSystemSum / samples.length,
6701-
user: thisProcessUserSum / samples.length,
6702-
});
6703-
}
6704-
samples.length = 0;
6705-
}
6706-
}, 15);
6707-
interval.unref();
6708-
6709-
return {
6710-
overall,
6711-
thisProcess,
6712-
details,
6713-
stop: () => {
6714-
clearInterval(interval);
6715-
},
6716-
};
6717-
};
6718-
67196551
const startMonitoringMetric = (measure) => {
67206552
const metrics = [];
67216553
const takeMeasure = () => {
@@ -6761,22 +6593,6 @@ const medianFromSortedArray = (array) => {
67616593
return medianNumber;
67626594
};
67636595

6764-
// https://gist.github.com/GaetanoPiazzolla/c40e1ebb9f709d091208e89baf9f4e00
6765-
6766-
6767-
const startMonitoringCpuUsage = () => {
6768-
const cpuUsage = startMeasuringTotalCpuUsage();
6769-
const processCpuUsageMonitoring = startMonitoringMetric(() => {
6770-
return cpuUsage.thisProcess.active;
6771-
});
6772-
const osCpuUsageMonitoring = startMonitoringMetric(() => {
6773-
return cpuUsage.overall.active;
6774-
});
6775-
const result = [processCpuUsageMonitoring, osCpuUsageMonitoring];
6776-
result.stop = cpuUsage.stop;
6777-
return result;
6778-
};
6779-
67806596
const startMonitoringMemoryUsage = () => {
67816597
const processMemoryUsageMonitoring = startMonitoringMetric(() => {
67826598
return memoryUsage().rss;
@@ -11231,4 +11047,4 @@ const escapeRegexpSpecialChars = (string) => {
1123111047
});
1123211048
};
1123311049

11234-
export { ANSI, Abort, CONTENT_TYPE, DATA_URL, JS_QUOTES, RUNTIME_COMPAT, UNICODE, URL_META, applyFileSystemMagicResolution, applyNodeEsmResolution, asSpecifierWithoutSearch, asUrlWithoutSearch, assertAndNormalizeDirectoryUrl, browserDefaultRuntimeCompat, bufferToEtag, clearDirectorySync, collectFiles, compareFileUrls, comparePathnames, composeTwoImportMaps, createDetailedMessage$1 as createDetailedMessage, createDynamicLog, createLogger, createLookupPackageDirectory, createTaskLog, distributePercentages, ensureEmptyDirectory, ensurePathnameTrailingSlash, ensureWindowsDriveLetter, errorToHTML, escapeRegexpSpecialChars, generateContentFrame, getCallerPosition, getExtensionsToTry, humanizeDuration, humanizeFileSize, humanizeMemory, inferRuntimeCompatFromClosestPackage, injectQueryParamIntoSpecifierWithoutEncoding, injectQueryParams, injectQueryParamsIntoSpecifier, isFileSystemPath, isSpecifierForNodeBuiltin, lookupPackageDirectory, moveUrl, nodeDefaultRuntimeCompat, normalizeImportMap, normalizeUrl, raceProcessTeardownEvents, readCustomConditionsFromProcessArgs, readEntryStatSync, readPackageAtOrNull, registerDirectoryLifecycle, renderBigSection, renderDetails, renderTable, renderUrlOrRelativeUrlFilename, resolveImport, setUrlBasename, setUrlExtension, setUrlFilename, startMonitoringCpuUsage, startMonitoringMemoryUsage, stringifyUrlSite, updateJsonFileSync, urlIsOrIsInsideOf, urlToBasename, urlToExtension$1 as urlToExtension, urlToFileSystemPath, urlToFilename$1 as urlToFilename, urlToPathname$1 as urlToPathname, urlToRelativeUrl, validateResponseIntegrity, writeFileSync };
11050+
export { ANSI, Abort, CONTENT_TYPE, DATA_URL, JS_QUOTES, RUNTIME_COMPAT, UNICODE, URL_META, applyFileSystemMagicResolution, applyNodeEsmResolution, asSpecifierWithoutSearch, asUrlWithoutSearch, assertAndNormalizeDirectoryUrl, browserDefaultRuntimeCompat, bufferToEtag, clearDirectorySync, collectFiles, compareFileUrls, comparePathnames, composeTwoImportMaps, createDetailedMessage$1 as createDetailedMessage, createDynamicLog, createLogger, createLookupPackageDirectory, createTaskLog, distributePercentages, ensureEmptyDirectory, ensurePathnameTrailingSlash, ensureWindowsDriveLetter, errorToHTML, escapeRegexpSpecialChars, generateContentFrame, getCallerPosition, getExtensionsToTry, humanizeDuration, humanizeFileSize, humanizeMemory, inferRuntimeCompatFromClosestPackage, injectQueryParamIntoSpecifierWithoutEncoding, injectQueryParams, injectQueryParamsIntoSpecifier, isFileSystemPath, isSpecifierForNodeBuiltin, lookupPackageDirectory, moveUrl, nodeDefaultRuntimeCompat, normalizeImportMap, normalizeUrl, raceProcessTeardownEvents, readCustomConditionsFromProcessArgs, readEntryStatSync, readPackageAtOrNull, registerDirectoryLifecycle, renderBigSection, renderDetails, renderTable, renderUrlOrRelativeUrlFilename, resolveImport, setUrlBasename, setUrlExtension, setUrlFilename, startMonitoringMemoryUsage, stringifyUrlSite, updateJsonFileSync, urlIsOrIsInsideOf, urlToBasename, urlToExtension$1 as urlToExtension, urlToFileSystemPath, urlToFilename$1 as urlToFilename, urlToPathname$1 as urlToPathname, urlToRelativeUrl, validateResponseIntegrity, writeFileSync };

dist/start_dev_server/start_dev_server.js

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,8 +2467,7 @@ const parseAndTransformJsReferences = async (
24672467
for (const sequentialAction of sequentialActions) {
24682468
await sequentialAction();
24692469
}
2470-
const { content, sourcemap } = magicSource.toContentAndSourcemap();
2471-
return { content, sourcemap };
2470+
return magicSource.toContentAndSourcemap();
24722471
};
24732472

24742473
const jsenvPluginReferenceExpectedTypes = () => {
@@ -6161,6 +6160,8 @@ const jsenvPluginImportMetaCss = () => {
61616160
inputIsJsModule: true,
61626161
inputUrl: urlInfo.originalUrl,
61636162
outputUrl: urlInfo.generatedUrl,
6163+
// the map would be dropped: the content sent back carries none
6164+
options: { sourceMaps: false },
61646165
});
61656166
if (code === urlInfo.content) {
61666167
// all assignments were already in array form (pre-built file) — nothing to do
@@ -8241,7 +8242,10 @@ const devServerPluginOmegaErrorHandler = () => {
82418242
status: 403,
82428243
};
82438244
}
8244-
return convertFileSystemErrorToResponseProperties(error);
8245+
// the dev server runs with canExposeSensitiveData: file paths are welcome
8246+
return convertFileSystemErrorToResponseProperties(error, {
8247+
canExposeSensitiveData: true,
8248+
});
82458249
};
82468250
const response = getResponseForError();
82478251
if (!response) {
@@ -8427,10 +8431,9 @@ const prependJsClassicInJsClassic = (jsUrlInfo, urlInfoToPrepend) => {
84278431
const magicSource = createMagicSource(jsUrlInfo.content);
84288432
magicSource.prepend(`${urlInfoToPrepend.content}\n\n`);
84298433
const magicResult = magicSource.toContentAndSourcemap();
8430-
const sourcemap = composeTwoSourcemaps(
8431-
jsUrlInfo.sourcemap,
8432-
magicResult.sourcemap,
8433-
);
8434+
const sourcemap = jsUrlInfo.context.sourcemapsEnabled
8435+
? composeTwoSourcemaps(jsUrlInfo.sourcemap, magicResult.sourcemap)
8436+
: null;
84348437
jsUrlInfo.mutateContent({
84358438
content: magicResult.content,
84368439
sourcemap,
@@ -8448,6 +8451,7 @@ const prependJsClassicInJsModule = async (jsUrlInfo, urlInfoToPrepend) => {
84488451
input: jsUrlInfo.content,
84498452
inputIsJsModule: true,
84508453
inputUrl: jsUrlInfo.originalUrl,
8454+
options: { sourceMaps: jsUrlInfo.context.sourcemapsEnabled },
84518455
});
84528456
jsUrlInfo.mutateContent({
84538457
content: code,
@@ -10172,7 +10176,6 @@ const createUrlInfoTransformer = ({
1017210176
contentAst, // undefined most of the time
1017310177
contentEtag, // in practice always undefined
1017410178
contentLength,
10175-
sourcemap,
1017610179
sourcemapIsWrong,
1017710180
contentInjections,
1017810181
} = transformations;
@@ -10199,11 +10202,14 @@ const createUrlInfoTransformer = ({
1019910202
contentLength,
1020010203
});
1020110204
}
10202-
if (
10203-
sourcemap &&
10204-
mayHaveSourcemap(urlInfo) &&
10205-
shouldHandleSourcemap(urlInfo)
10206-
) {
10205+
// "sourcemap" is read last, and only when it will be used: a plugin can
10206+
// hand it back as a getter that generates the map on first read, so that
10207+
// nothing is generated for a kitchen that throws sourcemaps away
10208+
const sourcemap =
10209+
mayHaveSourcemap(urlInfo) && shouldHandleSourcemap(urlInfo)
10210+
? transformations.sourcemap
10211+
: null;
10212+
if (sourcemap) {
1020710213
const sourcemapNormalized = normalizeSourcemap(urlInfo, sourcemap);
1020810214
let currentSourcemap = urlInfo.sourcemap;
1020910215
const finalSourcemap = composeTwoSourcemaps(
@@ -10236,6 +10242,14 @@ const createUrlInfoTransformer = ({
1023610242
writeInsideOutDirectory(urlInfo);
1023710243
};
1023810244

10245+
// Written synchronously on purpose, and measured: async is the tempting
10246+
// choice, but here it loses. A cold load cooks hundreds of files; their
10247+
// synchronous writes block the event loop ~160ms in total, while
10248+
// asynchronous writes queue in the threadpool behind tens of MB of content
10249+
// and sourcemaps, and a response that waits for its own write then waits
10250+
// ~36ms on average (18s summed over 500 responses). Not waiting is not an
10251+
// option either: the last write lands after the test that cooked it has
10252+
// ended, and the side-effect snapshots lose it.
1023910253
const writeInsideOutDirectory = (urlInfo) => {
1024010254
// writing result inside ".jsenv" directory (debug purposes)
1024110255
if (!outDirectoryUrl) {
@@ -10555,6 +10569,12 @@ const createKitchen = ({
1055510569
INJECTIONS,
1055610570
getPluginMeta: null,
1055710571
sourcemaps,
10572+
// a plugin producing a sourcemap can skip the work when it would be
10573+
// thrown away (see shouldHandleSourcemap in url_info_transformations.js)
10574+
sourcemapsEnabled:
10575+
sourcemaps === "inline" ||
10576+
sourcemaps === "file" ||
10577+
sourcemaps === "programmatic",
1055810578
outDirectoryUrl,
1055910579
},
1056010580
resolve: (specifier, importer = rootDirectoryUrl) => {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@
7575
"@jsenv/ast": "6.9.2",
7676
"@jsenv/js-module-fallback": "1.5.1",
7777
"@jsenv/plugin-bundling": "2.10.18",
78-
"@jsenv/plugin-minification": "1.7.9",
78+
"@jsenv/plugin-minification": "1.7.10",
7979
"@jsenv/plugin-supervisor": "1.8.13",
8080
"@jsenv/plugin-transpilation": "1.6.1",
81-
"@jsenv/server": "17.6.1",
81+
"@jsenv/server": "17.6.2",
8282
"@jsenv/sourcemap": "1.4.2",
8383
"react-table": "7.8.0"
8484
},

packages/backend/database-manager/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
},
3131
"dependencies": {
3232
"@jsenv/database": "0.0.15",
33-
"@jsenv/server": "17.6.1",
33+
"@jsenv/server": "17.6.2",
3434
"@jsenv/urls": "2.9.10",
3535
"@tanstack/table-core": "8.21.3",
3636
"jsonwebtoken": "9.0.3",

packages/backend/server/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ await startServer({
2525
- WebSocket and Server-Sent Events, with a broadcast helper
2626
- HTTPS, with http → https redirection; http2 as an option
2727
- CORS, server timing and error pages as plugins
28+
- Host header check (DNS rebinding) and bounded request bodies
2829
- A route inspector at `/.internal/route_inspector`
2930

3031
# Installation

0 commit comments

Comments
 (0)