Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Bump dependencies #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 0 additions & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
npx lint-staged
31 changes: 15 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"license": "MIT",
"scripts": {
"test": "ts-node --transpile-only test/test.ts",
"prepare": "husky install",
"prepare": "husky",
"watch": "esbuild ./src/index.js --outdir=build --bundle --platform=node --target=node16 --external:source-map --main-fields=main --sourcemap=linked --watch",
"build-plugin": "rm -rf build && esbuild src/index.ts --outdir=build --bundle --platform=node --target=node16 --external:source-map --main-fields=main --sourcemap=linked && cp src/types.ts build/index.d.ts",
"example": "./bundle.ts --main example/main.ts --worker example/worker.ts --outfile example/bundle.js && open example/index.html",
Expand All @@ -23,29 +23,28 @@
"dependencies": {
"acorn": "^8.7.0",
"acorn-walk": "^8.2.0",
"escope": "^3.6.0",
"magic-string": "^0.26.1",
"mkdirp": "^1.0.4",
"escope": "^4.0.0",
"magic-string": "^0.30.17",
"mkdirp": "^3.0",
"source-map": "^0.7.3",
"ts-node": "^10.7.0",
"typescript": "^4.6.2",
"typescript": "^5.4.0",
"yargs": "^17.4.0"
},
"peerDependencies": {
"esbuild": "^0.19.10"
"esbuild": "^0.21.0"
},
"devDependencies": {
"@types/estree": "^0.0.51",
"@types/mkdirp": "^1.0.2",
"@types/node": "^17.0.23",
"@types/estree": "^1.0.6",
"@types/node": "^20.0.0",
"@types/yargs": "^17.0.10",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0",
"esbuild": "^0.19.10",
"eslint": "^8.12.0",
"husky": ">=6",
"@typescript-eslint/eslint-plugin": "^8.18.1",
"@typescript-eslint/parser": "^8.18.1",
"esbuild": "^0.21.0",
"eslint": "^9.0.0",
"husky": ">=9",
"lint-staged": ">=10",
"prettier": "^2.6.1",
"puppeteer": "^19.5.2"
"prettier": "^3.4.2",
"puppeteer": "^20.0.0"
}
}
8 changes: 5 additions & 3 deletions src/assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export function assert(x: unknown, message: string): asserts x {
if (!x) {
throw new Error(message.split(' ').length ? message : `Expected ${message} to be truthy`);
}
if (!x) {
throw new Error(
message.split(" ").length ? message : `Expected ${message} to be truthy`,
);
}
}
2 changes: 1 addition & 1 deletion src/escope.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ declare module "escope" {
ignoreEval?: boolean;
sourceType?: "script" | "module";
ecmaVersion: number;
}
},
): ScopeManager;

class ScopeManager {
Expand Down
26 changes: 13 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const inlineDedupedWorker: typeof public_types.inlineDedupedWorker =

assert(
!Array.isArray(initialOptions.entryPoints),
"entryPoints should be an object"
"entryPoints should be an object",
);

if (
Expand All @@ -53,14 +53,14 @@ export const inlineDedupedWorker: typeof public_types.inlineDedupedWorker =
Object.keys(initialOptions.entryPoints).length !== 2
) {
throw new Error(
`Expected entryPoints to be an object of the form {main: ..., worker: ...}.`
`Expected entryPoints to be an object of the form {main: ..., worker: ...}.`,
);
}

const mainEntryPoint = initialOptions.entryPoints.main;

const createWorkerPattern = new RegExp(
"^" + escapeRegExp(createWorkerModule) + "$"
"^" + escapeRegExp(createWorkerModule) + "$",
);

let foundCreateWorker = false;
Expand Down Expand Up @@ -95,19 +95,19 @@ export const inlineDedupedWorker: typeof public_types.inlineDedupedWorker =
result.outputFiles.filter((o) => o.path.endsWith(".js")).length ===
3,
`Expected exactly 3 JS output files but found ${result.outputFiles.map(
(f) => f.path
)}`
(f) => f.path,
)}`,
);

const mainBundle = result.outputFiles.find((o) =>
o.path.endsWith("main.js")
o.path.endsWith("main.js"),
);
const workerBundle = result.outputFiles.find((o) =>
o.path.endsWith("worker.js")
o.path.endsWith("worker.js"),
);
const sharedBundle = result.outputFiles.find(
(o) =>
o.path.endsWith(".js") && o.path.indexOf("__shared_chunk") >= 0
o.path.endsWith(".js") && o.path.indexOf("__shared_chunk") >= 0,
);
assert(workerBundle, "workerBundle");
assert(mainBundle, "mainBundle");
Expand All @@ -116,13 +116,13 @@ export const inlineDedupedWorker: typeof public_types.inlineDedupedWorker =
let sourcemaps;
if (initialOptions.sourcemap) {
const main = result.outputFiles.find(
(o) => o.path === mainBundle.path + ".map"
(o) => o.path === mainBundle.path + ".map",
)?.text;
const worker = result.outputFiles.find(
(o) => o.path === workerBundle.path + ".map"
(o) => o.path === workerBundle.path + ".map",
)?.text;
const shared = result.outputFiles.find(
(o) => o.path === sharedBundle.path + ".map"
(o) => o.path === sharedBundle.path + ".map",
)?.text;
assert(main, "main sourcemap");
assert(worker, "worker sourcemap");
Expand All @@ -145,11 +145,11 @@ export const inlineDedupedWorker: typeof public_types.inlineDedupedWorker =
initialOptions.outfile ||
path.resolve(
initialOptions.outdir || process.cwd(),
basename.replace(/(\.ts|\.js)?$/, ".js")
basename.replace(/(\.ts|\.js)?$/, ".js"),
);

const cssFiles = result.outputFiles.filter((f) =>
f.path.endsWith(".css")
f.path.endsWith(".css"),
);

if (splitOutdir) {
Expand Down
10 changes: 5 additions & 5 deletions src/inline-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async function inlineWorkerWithEvalStyle(opts: {
const WORKER_MODULE_SRC = variable("worker_module");
const WORKER_SOURCE = variable("worker_source");
const WORKER_SHARED_MODULE_EXPORTS_REFERENCE = variable(
"worker_shared_module_exports"
"worker_shared_module_exports",
);

mainMs.prepend(
Expand Down Expand Up @@ -124,7 +124,7 @@ async function inlineWorkerWithEvalStyle(opts: {

return {createWorker, default: {createWorker}};
})();
`
`,
);

mainMs.prepend(`(() => {`).append(`})()`);
Expand Down Expand Up @@ -229,7 +229,7 @@ async function inlineWorkerWithClosureStyle(opts: {

return {createWorker, default: {createWorker}};
})();
`
`,
);

const bundle = new Bundle();
Expand Down Expand Up @@ -262,12 +262,12 @@ async function inlineWorkerWithClosureStyle(opts: {
addSourceMappingLocations(sourcemaps.worker, workerMs);

const bundleMap = SourceMapGenerator.fromSourceMap(
await new SourceMapConsumer(bundle.generateMap({ includeContent: true }))
await new SourceMapConsumer(bundle.generateMap({ includeContent: true })),
);
for (const chunk in sourcemaps) {
bundleMap.applySourceMap(
sourcemaps[chunk as keyof typeof sourcemaps],
`<inline-worker-dedupe:${chunk}>`
`<inline-worker-dedupe:${chunk}>`,
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/replace-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function replaceExports(
context: Context,
code: MagicString,
namedExportsObjectVariable: string | undefined,
defaultExportVariable: string | undefined
defaultExportVariable: string | undefined,
) {
context.time("repaceExports::acorn");
const node = acorn.parse(code.original, {
Expand Down Expand Up @@ -40,7 +40,7 @@ export function replaceExports(

function compileExport(
e: estree.ExportNamedDeclaration,
target: string | undefined
target: string | undefined,
) {
if (!e.declaration) {
// If we aren't assigning the exports to anything, we don't actually need to write any code,
Expand All @@ -50,7 +50,7 @@ function compileExport(
return e.specifiers
.map(
(spec) =>
`Object.defineProperty(${target}, '${spec.exported.name}', { get: () => ${spec.local.name} });`
`Object.defineProperty(${target}, '${spec.exported.name}', { get: () => ${spec.local.name} });`,
)
.join("\n");
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/replace-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Context } from "./context";
export function replaceImports(
context: Context,
code: MagicString,
getExportsObjectName: (i: estree.ImportDeclaration) => string | false
getExportsObjectName: (i: estree.ImportDeclaration) => string | false,
) {
context.time("replaceImports::acorn");
const ast = acorn.parse(code.original, {
Expand All @@ -30,7 +30,7 @@ export function replaceImports(

assert(ast.type === "Program", `Unexpected top-level node ${ast.type}`);
const imports = ast.body.filter(
(n): n is estree.ImportDeclaration => n.type === "ImportDeclaration"
(n): n is estree.ImportDeclaration => n.type === "ImportDeclaration",
);
const importIdentifiers = new Map<estree.Identifier, string>();
for (const declaration of imports) {
Expand All @@ -46,8 +46,8 @@ export function replaceImports(
spec.type === "ImportNamespaceSpecifier"
? exportsObjectName
: spec.type === "ImportDefaultSpecifier"
? `${exportsObjectName}.default`
: `${exportsObjectName}['${spec.imported.name}']`;
? `${exportsObjectName}.default`
: `${exportsObjectName}['${spec.imported.name}']`;

importIdentifiers.set(spec.local, replacement);
}
Expand All @@ -71,7 +71,7 @@ export function replaceImports(
const replacement = importIdentifiers.get(identifier);
if (replacement) {
const parent = parents.get(
ref.identifier as unknown as acorn.Node
ref.identifier as unknown as acorn.Node,
) as estree.Node;
if (parent?.type === "Property" && parent.shorthand) {
code.appendRight(range[1], `: ${replacement}`);
Expand Down
2 changes: 1 addition & 1 deletion src/source-maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RawSourceMap } from "source-map";

export function inlineSourceMapComment(map: string | RawSourceMap) {
const b64 = Buffer.from(
typeof map === "string" ? map : JSON.stringify(map)
typeof map === "string" ? map : JSON.stringify(map),
).toString("base64");
return `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${b64}`;
}
6 changes: 3 additions & 3 deletions test/basic/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
declare module 'create-worker' {
export const createWorker: () => Worker;
}
declare module "create-worker" {
export const createWorker: () => Worker;
}
2 changes: 1 addition & 1 deletion test/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class Driver {
constructor(
private options: {
debug?: boolean;
}
},
) {}

async destroy() {
Expand Down
10 changes: 5 additions & 5 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const perStyleTests: {
assert.deepEqual(errors, [], "no errors");
assert.ok(
result.main && result.worker && result.main !== result.worker,
"Worker loaded and worked"
"Worker loaded and worked",
);
},
},
Expand Down Expand Up @@ -95,7 +95,7 @@ const perStyleTests: {
assert.deepEqual(errors, [], "no errors");
assert.ok(
result.main && result.worker && result.main !== result.worker,
"Worker loaded and worked"
"Worker loaded and worked",
);
},
},
Expand Down Expand Up @@ -138,7 +138,7 @@ const perStyleTests: {
assert.deepEqual(errors, [], "no errors");
assert.ok(
result.main && result.worker && result.main !== result.worker,
"Worker loaded and worked"
"Worker loaded and worked",
);
},
},
Expand All @@ -153,12 +153,12 @@ const API = { prop };`;
replaceImports(
new Context({ logLevel: "silent" }),
ms,
() => `__sharedModuleExports`
() => `__sharedModuleExports`,
);

assert.equal(
ms.toString().trim(),
`const API = { prop: __sharedModuleExports['prop'] };`
`const API = { prop: __sharedModuleExports['prop'] };`,
);
},
},
Expand Down
12 changes: 6 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */

/* Language and Environment */
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
Expand All @@ -24,7 +24,7 @@
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */

/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
"module": "commonjs" /* Specify what module code is generated. */,
// "rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
Expand Down Expand Up @@ -69,12 +69,12 @@
/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,

/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
// "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
Expand All @@ -96,6 +96,6 @@

/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}
Loading