Skip to content

Commit

Permalink
💥 Drop std/node support
Browse files Browse the repository at this point in the history
  • Loading branch information
wojpawlik committed Jul 19, 2023
1 parent 70cddb3 commit cc7d7c1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ name: CI
on:
pull_request:
push:
branches: [ main ]
branches:
- 'main'
- 'v[0-9]+'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm ci --ignore-scripts
- run: npm install --ignore-scripts
- run: echo "$PWD/node_modules/.bin" >> "$GITHUB_PATH"
- run: deno test --no-run
- run: deno lint
Expand All @@ -19,5 +21,5 @@ jobs:
- run: lib/cli.js --outDir nodejs/
- run: git diff --no-index lib/ nodejs/

- run: deno test --allow-read=.
- run: deno test --allow-read=. src/
- run: fdt lib/**/*.test.js
40 changes: 21 additions & 19 deletions src/_transformations/specifiers.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
import { Node, type SourceFile } from "../deps.deno.ts";
import * as re from "../util/regexp.ts";

export const name = /(?:@[\w.-]+\/)?[\w.-]+/;
const version = /[^/?]+/;
export const services = ["npm:", "https://esm.sh/", "https://cdn.skypack.dev/"];
export const name = /^(?:@[\w.-]+\/)?[\w.-]+$/;
const version = /^@[^/?]+$/;
const path = /\/[^?]*/;
const url = re.tag()`^${re.union(services)}(${name})${version}?(${path})?.*$`;

const patterns = [
re.tag()`^npm:(${name})(?:@${version})?(${path})?`,
re.tag()`^https://esm\.sh/(${name})(?:@${version})?(${path})?`,
re.tag()`^https://cdn\.skypack\.dev/(${name})(?:@${version})?(${path})?`,
re.tag()`^https://deno\.land/std(?:@${version})?/node/([\w/]+)\.ts$`,
re.tag()`^https://nest\.land/std/node/${version}/([\w/]+)\.ts$`,
];

const transpileHttpsImport = (specifier: string) => {
for (const pattern of patterns) {
const match = pattern.exec(specifier);
if (match === null) continue;
const [, pkg, path = ""] = match;
return pkg + path;
}
return specifier;
};
const transpileHttpsImport = (specifier: string) =>
specifier.replace(url, "$1$2");

const transpileRelativeImport = (specifier: string) =>
specifier
Expand All @@ -33,3 +21,17 @@ export const transpileSpecifier = (specifier: string) => {
if (isRelative(specifier)) return transpileRelativeImport(specifier);
return transpileHttpsImport(specifier);
};

export function transpileSpecifiers(sourceFile: SourceFile) {
for (const statement of sourceFile.getStatements()) {
if (
Node.isImportDeclaration(statement) ||
Node.isExportDeclaration(statement)
) {
const modSpecifierValue = statement.getModuleSpecifierValue();
if (modSpecifierValue !== undefined) {
statement.setModuleSpecifier(transpileSpecifier(modSpecifierValue));
}
}
}
}
2 changes: 1 addition & 1 deletion src/util/regexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type RegExpSource = Pick<RegExp, "source">;
const _source = (arg: string | RegExpSource) =>
typeof arg === "string"
? arg.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") // escape string
: arg.source;
: arg.source.replace(/^\^|\$$/g, "");

export const tag = (flags = "") =>
(
Expand Down

0 comments on commit cc7d7c1

Please sign in to comment.