Skip to content

[v22.x backport] crypto: fix SHAKE128/256 breaking change introduced with OpenSSL 3.4 #58960

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

Open
wants to merge 17 commits into
base: v22.x-staging
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
2 changes: 1 addition & 1 deletion benchmark/ts/strip-typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const bench = common.createBenchmark(main, {
filepath: [ts, js],
n: [1e4],
}, {
flags: ['--experimental-strip-types', '--disable-warning=ExperimentalWarning'],
flags: ['--disable-warning=ExperimentalWarning'],
});

async function main({ n, filepath }) {
Expand Down
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.26',
'v8_embedder_string': '-node.27',

##### V8 defaults for Node.js #####

Expand Down
45 changes: 35 additions & 10 deletions deps/amaro/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Amaro

Amaro is a wrapper around `@swc/wasm-typescript`, a WebAssembly port of the SWC TypeScript parser.
It's currently used as an internal in Node.js for [Type Stripping](https://github.com/nodejs/loaders/issues/208), but in the future it will be possible to be upgraded separately by users.
The main goal of this package is to provide a stable API for TypeScript parser, which is unstable and subject to change.
It's used as an internal in Node.js for [Type Stripping](https://nodejs.org/api/typescript.html#type-stripping) but can also be used as a standalone package.

> Amaro means "bitter" in Italian. It's a reference to [Mount Amaro](https://en.wikipedia.org/wiki/Monte_Amaro_(Abruzzo)) on whose slopes this package was conceived.

This package provides a stable API for the TypeScript parser and allows users to upgrade to the latest version of TypeScript transpiler independently from the one used internally in Node.js.

## How to Install

To install Amaro, run:
Expand All @@ -29,29 +30,53 @@ console.log(code); // "const foo = 'bar';"

It is possible to use Amaro as an external loader to execute TypeScript files.
This allows the installed Amaro to override the Amaro version used by Node.js.
In order to use Amaro as an external loader, type stripping needs to be enabled.

```bash
node --experimental-strip-types --import="amaro/register" script.ts
```

Or with the alias:
In node v23 and later you can omit the `--experimental-strip-types` flag, as it is enabled by default.

```bash
node --experimental-strip-types --import="amaro/strip" script.ts
node --experimental-strip-types --import="amaro/strip" file.ts
```

Enabling TypeScript feature transformation:

```bash
node --experimental-transform-types --import="amaro/transform" script.ts
node --experimental-transform-types --import="amaro/transform" file.ts
```

> Note that the "amaro/transform" loader should be used with `--experimental-transform-types` flag, or
> at least with `--enable-source-maps` flag, to preserve the original source maps.

#### Type stripping in dependencies

Contrary to the Node.js [TypeScript support](https://nodejs.org/docs/latest/api/typescript.html#type-stripping-in-dependencies), when used as a loader, Amaro handles TypeScript files inside folders under a `node_modules` path.

### Monorepo usage

Amaro makes working in monorepos smoother by removing the need to rebuild internal packages during development. When used with the [`--conditions`](https://nodejs.org/docs/latest/api/cli.html#-c-condition---conditionscondition) flag, you can reference TypeScript source files directly in exports:

```json
"exports": {
".": {
"typescript": "./src/index.ts",
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"import": "./dist/index.js"
}
}
```

Then run your app with:

```bash
node --watch --import="amaro/strip" --conditions=typescript ./src/index.ts
```

This setup allows Node.js to load TypeScript files from linked packages without a build step. Changes to any package are picked up immediately, speeding up and simplifying local development in monorepos.

### TypeScript Version

The supported TypeScript version is 5.5.4, except the stage 3 decorator proposal.
The supported TypeScript version is 5.8.

## License (MIT)

Expand Down
13 changes: 13 additions & 0 deletions deps/amaro/dist/errors.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type SwcError = {
code: "UnsupportedSyntax" | "InvalidSyntax";
message: string;
startColumn: number;
startLine: number;
snippet: string;
filename: string;
endColumn: number;
endLine: number;
};
export declare function isSwcError(error: unknown): error is SwcError;
export declare function wrapAndReThrowSwcError(error: SwcError): never;
export {};
11 changes: 9 additions & 2 deletions deps/amaro/dist/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ export function isSwcError(error) {
return error.code !== void 0;
}
export function wrapAndReThrowSwcError(error) {
const errorHints = `${error.filename}:${error.startLine}
${error.snippet}
`;
switch (error.code) {
case "UnsupportedSyntax": {
const unsupportedSyntaxError = new Error(error.message);
unsupportedSyntaxError.name = "UnsupportedSyntaxError";
unsupportedSyntaxError.stack = `${errorHints}${unsupportedSyntaxError.stack}`;
throw unsupportedSyntaxError;
}
case "InvalidSyntax":
throw new SyntaxError(error.message);
case "InvalidSyntax": {
const syntaxError = new SyntaxError(error.message);
syntaxError.stack = `${errorHints}${syntaxError.stack}`;
throw syntaxError;
}
default:
throw new Error(error.message);
}
Expand Down
1 change: 1 addition & 0 deletions deps/amaro/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { transformSync } from "./transform.ts";
27 changes: 21 additions & 6 deletions deps/amaro/dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion deps/amaro/dist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"강동윤 <[email protected]>"
],
"description": "wasm module for swc",
"version": "1.11.5",
"version": "1.12.1",
"license": "Apache-2.0",
"repository": {
"type": "git",
Expand Down
2 changes: 2 additions & 0 deletions deps/amaro/dist/strip-loader.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { LoadFnOutput, LoadHookContext } from "node:module";
export declare function load(url: string, context: LoadHookContext, nextLoad: (url: string, context?: LoadHookContext) => LoadFnOutput | Promise<LoadFnOutput>): Promise<LoadFnOutput>;
4 changes: 3 additions & 1 deletion deps/amaro/dist/strip-loader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict";
import { fileURLToPath } from "node:url";
import { isSwcError, wrapAndReThrowSwcError } from "./errors.js";
import { transformSync } from "./index.js";
export async function load(url, context, nextLoad) {
Expand All @@ -10,7 +11,8 @@ export async function load(url, context, nextLoad) {
format: "module"
});
const { code } = transformSync(source.toString(), {
mode: "strip-only"
mode: "strip-only",
filename: fileURLToPath(url)
});
return {
format: format.replace("-typescript", ""),
Expand Down
2 changes: 2 additions & 0 deletions deps/amaro/dist/transform-loader.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { LoadFnOutput, LoadHookContext } from "node:module";
export declare function load(url: string, context: LoadHookContext, nextLoad: (url: string, context?: LoadHookContext) => LoadFnOutput | Promise<LoadFnOutput>): Promise<LoadFnOutput>;
3 changes: 2 additions & 1 deletion deps/amaro/dist/transform-loader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict";
import { fileURLToPath } from "node:url";
import { isSwcError, wrapAndReThrowSwcError } from "./errors.js";
import { transformSync } from "./index.js";
export async function load(url, context, nextLoad) {
Expand All @@ -12,7 +13,7 @@ export async function load(url, context, nextLoad) {
const { code, map } = transformSync(source.toString(), {
mode: "transform",
sourceMap: true,
filename: url
filename: fileURLToPath(url)
});
let output = code;
if (map) {
Expand Down
2 changes: 2 additions & 0 deletions deps/amaro/dist/transform.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { Options, TransformOutput } from "../lib/wasm";
export declare function transformSync(source: string, options?: Options): TransformOutput;
59 changes: 59 additions & 0 deletions deps/amaro/lib/wasm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* tslint:disable */
/* eslint-disable */

export declare function transform(src: string | Uint8Array, opts?: Options): Promise<TransformOutput>;
export declare function transformSync(src: string | Uint8Array, opts?: Options): TransformOutput;
export type { Options, TransformOutput };



interface Options {
module?: boolean;
filename?: string;
mode?: Mode;
transform?: TransformConfig;
deprecatedTsModuleAsError?: boolean;
sourceMap?: boolean;
}

interface TransformConfig {
/**
* @see https://www.typescriptlang.org/tsconfig#verbatimModuleSyntax
*/
verbatimModuleSyntax?: boolean;
/**
* Native class properties support
*/
nativeClassProperties?: boolean;
importNotUsedAsValues?: "remove" | "preserve";
/**
* Don't create `export {}`.
* By default, strip creates `export {}` for modules to preserve module
* context.
*
* @see https://github.com/swc-project/swc/issues/1698
*/
noEmptyExport?: boolean;
importExportAssignConfig?: "Classic" | "Preserve" | "NodeNext" | "EsNext";
/**
* Disables an optimization that inlines TS enum member values
* within the same module that assumes the enum member values
* are never modified.
*
* Defaults to false.
*/
tsEnumIsMutable?: boolean;
}



type Mode = "strip-only" | "transform";



interface TransformOutput {
code: string;
map?: string;
}


12 changes: 12 additions & 0 deletions deps/amaro/lib/wasm_bg.wasm.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* tslint:disable */
/* eslint-disable */
export const memory: WebAssembly.Memory;
export const transform: (a: number, b: number) => number;
export const transformSync: (a: number, b: number, c: number) => void;
export const __wbindgen_export_0: (a: number) => void;
export const __wbindgen_export_1: WebAssembly.Table;
export const __wbindgen_export_2: (a: number, b: number) => number;
export const __wbindgen_export_3: (a: number, b: number, c: number, d: number) => number;
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
export const __wbindgen_export_4: (a: number, b: number, c: number) => void;
export const __wbindgen_export_5: (a: number, b: number, c: number, d: number) => void;
17 changes: 12 additions & 5 deletions deps/amaro/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "amaro",
"version": "0.4.1",
"version": "1.1.0",
"description": "Node.js TypeScript wrapper",
"license": "MIT",
"type": "commonjs",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"homepage": "https://github.com/nodejs/amaro#readme",
"bugs": {
"url": "https://github.com/nodejs/amaro/issues"
Expand All @@ -13,6 +14,12 @@
"type": "git",
"url": "https://github.com/nodejs/amaro.git"
},
"keywords": [
"typescript",
"nodejs",
"type stripping",
"strip-types"
],
"scripts": {
"clean": "rimraf dist",
"lint": "biome lint --write",
Expand All @@ -21,11 +28,11 @@
"ci:fix": "biome check --write",
"prepack": "npm run build",
"postpack": "npm run clean",
"build": "node esbuild.config.mjs",
"build": "node esbuild.config.mjs && tsc --noCheck",
"build:wasm": "node tools/build-wasm.js",
"typecheck": "tsc --noEmit",
"test": "node --test --experimental-test-snapshots \"**/*.test.js\"",
"test:regenerate": "node --test --experimental-test-snapshots --test-update-snapshots \"**/*.test.js\""
"test": "node --test \"**/*.test.js\"",
"test:regenerate": "node --test --test-update-snapshots \"**/*.test.js\""
},
"devDependencies": {
"@biomejs/biome": "1.8.3",
Expand All @@ -37,12 +44,12 @@
},
"exports": {
".": "./dist/index.js",
"./register": "./dist/register-strip.mjs",
"./strip": "./dist/register-strip.mjs",
"./transform": "./dist/register-transform.mjs"
},
"files": [
"dist",
"lib/**/*.d.ts",
"LICENSE.md"
],
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/heap/cppgc/marking-state.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class MutatorMarkingState final : public BasicMarkingState {
~MutatorMarkingState() override = default;

inline bool MarkNoPush(HeapObjectHeader& header) {
return MutatorMarkingState::BasicMarkingState::MarkNoPush(header);
return BasicMarkingState::MarkNoPush(header);
}

inline void ReTraceMarkedWeakContainer(cppgc::Visitor&, HeapObjectHeader&);
Expand Down
Loading
Loading