From a1d7123c81fab7ef1e63b309917dc5ad3f21c8d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Sat, 18 Nov 2023 10:38:53 +0000 Subject: [PATCH 1/3] fix: fix `ModuleGraph` type export --- .eslintrc.cjs | 2 +- node/index.ts | 3 +- node/server/server.ts | 5 +- .../vendor/module_graph}/media_type.ts | 0 .../vendor/module_graph/module_graph.ts | 101 +++++++++--------- package.json | 4 +- 6 files changed, 57 insertions(+), 58 deletions(-) rename {deno/vendor/deno.land/x/deno_graph@0.59.2 => node/vendor/module_graph}/media_type.ts (100%) rename deno/vendor/deno.land/x/deno_graph@0.59.2/types.d.ts => node/vendor/module_graph/module_graph.ts (82%) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index be638ea3..6a880679 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -4,7 +4,7 @@ const { overrides } = require('@netlify/eslint-config-node') module.exports = { extends: '@netlify/eslint-config-node', - ignorePatterns: ['deno/**/*', 'test/deno/**/*', 'test/fixtures/**/*'], + ignorePatterns: ['deno/**/*', 'node/vendor/**', 'test/deno/**/*', 'test/fixtures/**/*'], parserOptions: { sourceType: 'module', }, diff --git a/node/index.ts b/node/index.ts index 8dfdc373..88babb3c 100644 --- a/node/index.ts +++ b/node/index.ts @@ -6,5 +6,6 @@ export type { EdgeFunction } from './edge_function.js' export { findFunctions as find } from './finder.js' export { generateManifest } from './manifest.js' export type { EdgeFunctionConfig, Manifest } from './manifest.js' -export { ModuleGraph, serve } from './server/server.js' +export type { ModuleGraphJson as ModuleGraph } from './vendor/module_graph/module_graph.js' +export { serve } from './server/server.js' export { validateManifest, ManifestValidationError } from './validation/manifest/index.js' diff --git a/node/server/server.ts b/node/server/server.ts index 6998a625..090cc013 100644 --- a/node/server/server.ts +++ b/node/server/server.ts @@ -1,7 +1,6 @@ import { readdir, unlink } from 'fs/promises' import { join } from 'path' -import type { ModuleGraphJson } from '../../deno/vendor/deno.land/x/deno_graph@0.59.2/types.d.js' import { DenoBridge, OnAfterDownloadHook, OnBeforeDownloadHook, ProcessRef } from '../bridge.js' import { getFunctionConfig, FunctionConfig } from '../config.js' import type { EdgeFunction } from '../edge_function.js' @@ -11,11 +10,11 @@ import { ImportMap } from '../import_map.js' import { getLogger, LogFunction, Logger } from '../logger.js' import { vendorNPMSpecifiers } from '../npm_dependencies.js' import { ensureLatestTypes } from '../types.js' +import type { ModuleGraphJson } from '../vendor/module_graph/module_graph.js' import { killProcess, waitForServer } from './util.js' export type FormatFunction = (name: string) => string -export type ModuleGraph = ModuleGraphJson interface PrepareServerOptions { basePath: string @@ -73,7 +72,7 @@ const prepareServer = ({ await killProcess(processRef.ps) } - let graph: ModuleGraph = { + let graph: ModuleGraphJson = { roots: [], modules: [], redirects: {}, diff --git a/deno/vendor/deno.land/x/deno_graph@0.59.2/media_type.ts b/node/vendor/module_graph/media_type.ts similarity index 100% rename from deno/vendor/deno.land/x/deno_graph@0.59.2/media_type.ts rename to node/vendor/module_graph/media_type.ts diff --git a/deno/vendor/deno.land/x/deno_graph@0.59.2/types.d.ts b/node/vendor/module_graph/module_graph.ts similarity index 82% rename from deno/vendor/deno.land/x/deno_graph@0.59.2/types.d.ts rename to node/vendor/module_graph/module_graph.ts index ab62ac52..0285b9b8 100644 --- a/deno/vendor/deno.land/x/deno_graph@0.59.2/types.d.ts +++ b/node/vendor/module_graph/module_graph.ts @@ -1,6 +1,8 @@ +/* eslint-disable */ +/* prettier-ignore */ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import type { MediaType } from "./media_type.ts"; +import type { MediaType } from './media_type.js' /** Additional meta data that is used to enrich the output of the module * graph. */ @@ -8,87 +10,87 @@ export interface CacheInfo { /** The string path to where the local version of the content is located. For * non `file:` URLs, this is the location of the cached content, otherwise it * is the absolute path to the local file. */ - local?: string; + local?: string /** The string path to where a transpiled version of the source content is * located, if any. */ - emit?: string; + emit?: string /** The string path to where an external source map of the transpiled source * content is located, if any. */ - map?: string; + map?: string } export interface TypesDependency { /** The string URL to the type information for the module. */ - types: string; + types: string /** An optional range which indicates the source of the dependency. */ - source?: Range; + source?: Range } export interface LoadResponseModule { /** A module with code has been loaded. */ - kind: "module"; + kind: 'module' /** The string URL of the resource. If there were redirects, the final * specifier should be set here, otherwise the requested specifier. */ - specifier: string; + specifier: string /** For remote resources, a record of headers should be set, where the key's * have been normalized to be lower case values. */ - headers?: Record; + headers?: Record /** The string value of the loaded resources. */ - content: string; + content: string } export interface LoadResponseExternal { /** The loaded module is either _external_ or _built-in_ to the runtime. */ - kind: "external"; + kind: 'external' /** The strung URL of the resource. If there were redirects, the final * specifier should be set here, otherwise the requested specifier. */ - specifier: string; + specifier: string } -export type LoadResponse = LoadResponseModule | LoadResponseExternal; +export type LoadResponse = LoadResponseModule | LoadResponseExternal export interface PositionJson { /** The line number of a position within a source file. The number is a zero * based index. */ - line: number; + line: number /** The character number of a position within a source file. The number is a * zero based index. */ - character: number; + character: number } export interface Range { /** A string URL representing a source of a dependency. */ - specifier: string; + specifier: string /** The start location of a range of text in a source file. */ - start?: PositionJson; + start?: PositionJson /** The end location of a range of text in a source file. */ - end?: PositionJson; + end?: PositionJson } export interface RangeJson { /** The start location of a range of text in a source file. */ - start: PositionJson; + start: PositionJson /** The end location of a range of text in a source file. */ - end: PositionJson; + end: PositionJson } export interface ResolvedDependency { /** The fully resolved string URL of the dependency, which should be * resolvable in the module graph. If there was an error, `error` will be set * and this will be undefined. */ - specifier?: string; + specifier?: string /** Any error encountered when trying to resolved the specifier. If this is * defined, `specifier` will be undefined. */ - error?: string; + error?: string /** The range within the source code where the specifier was identified. */ - span: RangeJson; + span: RangeJson } export interface TypesDependencyJson { /** The string specifier that was used for the dependency. */ - specifier: string; + specifier: string /** An object pointing to the resolved dependency. */ - dependency: ResolvedDependency; + dependency: ResolvedDependency } /** The kind of module. @@ -99,56 +101,52 @@ export interface TypesDependencyJson { * Dependency analysis is not performed for asserted or Script modules * currently. Synthetic modules were injected into the graph with their own * dependencies provided. */ -export type ModuleKind = - | "asserted" - | "esm" - | "npm" - | "external"; +export type ModuleKind = 'asserted' | 'esm' | 'npm' | 'external' export interface DependencyJson { /** The string specifier that was used for the dependency. */ - specifier: string; + specifier: string /** An object pointing to the resolved _code_ dependency. */ - code?: ResolvedDependency; + code?: ResolvedDependency /** An object pointing to the resolved _type_ dependency of a module. This is * populated when the `@deno-types` directive was used to supply a type * definition file for a dependency. */ - type?: ResolvedDependency; + type?: ResolvedDependency /** A flag indicating if the dependency was dynamic. (e.g. * `await import("mod.ts")`) */ - isDynamic?: true; - assertionType?: string; + isDynamic?: true + assertionType?: string } // todo(dsherret): split this up into separate types based on the "kind" export interface ModuleJson extends CacheInfo { /** The string URL of the module. */ - specifier: string; + specifier: string /** Any error encountered when attempting to load the module. */ - error?: string; + error?: string /** The module kind that was determined when the module was resolved. This is * used by loaders to indicate how a module needs to be loaded at runtime. */ - kind?: ModuleKind; + kind?: ModuleKind /** An array of dependencies that were identified in the module. */ - dependencies?: DependencyJson[]; + dependencies?: DependencyJson[] /** If the module had a types dependency, the information about that * dependency. */ - typesDependency?: TypesDependencyJson; + typesDependency?: TypesDependencyJson /** The resolved media type of the module, which determines how Deno will * handle the module. */ - mediaType?: MediaType; + mediaType?: MediaType /** The size of the source content of the module in bytes. */ - size?: number; + size?: number } export interface GraphImportJson { /** The referrer (URL string) that was used as a base when resolving the * imports added to the graph. */ - referrer: string; + referrer: string /** An array of resolved dependencies which were imported using the * referrer. */ - dependencies?: DependencyJson[]; + dependencies?: DependencyJson[] } /** The plain-object representation of a module graph that is suitable for @@ -156,27 +154,28 @@ export interface GraphImportJson { export interface ModuleGraphJson { /** The module specifiers (URL string) of the _roots_ of the module graph of * which the module graph was built for. */ - roots: string[]; + roots: string[] /** An array of modules that are part of the module graph. */ - modules: ModuleJson[]; + modules: ModuleJson[] /** External imports that were added to the graph when it was being built. * The key is the referrer which was used as a base to resolve the * dependency. The value is the resolved dependency. */ - imports?: GraphImportJson[]; + imports?: GraphImportJson[] /** A record/map of any redirects encountered when resolving modules. The * key was the requested module specifier and the value is the redirected * module specifier. */ - redirects: Record; + redirects: Record } export interface Dependency { /** An object pointing to the resolved _code_ dependency. */ - code?: ResolvedDependency; + code?: ResolvedDependency /** An object pointing to the resolved _type_ dependency of a module. This is * populated when the `@deno-types` directive was used to supply a type * definition file for a dependency. */ - type?: ResolvedDependency; + type?: ResolvedDependency /** A flag indicating if the dependency was dynamic. (e.g. * `await import("mod.ts")`) */ - isDynamic?: true; + isDynamic?: true } +/* eslint-enable */ diff --git a/package.json b/package.json index d9e75abc..eaebd3f6 100644 --- a/package.json +++ b/package.json @@ -35,11 +35,11 @@ "test:ci:vitest": "vitest run --coverage", "test:ci:deno": "deno test --allow-all deno", "test:integration": "node --experimental-modules test/integration/test.js", - "vendor": "deno vendor --force --output deno/vendor https://deno.land/x/deno_graph@0.59.2/types.d.ts https://deno.land/x/eszip@v0.55.2/mod.ts https://deno.land/x/retry@v2.0.0/mod.ts https://deno.land/x/std@0.177.0/path/mod.ts" + "vendor": "deno vendor --force --output deno/vendor https://deno.land/x/eszip@v0.55.2/mod.ts https://deno.land/x/retry@v2.0.0/mod.ts https://deno.land/x/std@0.177.0/path/mod.ts" }, "config": { "eslint": "--ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"{node,scripts,.github}/**/*.{js,ts,md,html}\" \"*.{js,ts,md,html}\"", - "prettier": "--ignore-path .gitignore --loglevel=warn \"{node,scripts,.github}/**/*.{js,ts,md,yml,json,html}\" \"*.{js,ts,yml,json,html}\" \".*.{js,ts,yml,json,html}\" \"!**/package-lock.json\" \"!package-lock.json\"" + "prettier": "--ignore-path .gitignore --loglevel=warn \"{node,scripts,.github}/**/*.{js,ts,md,yml,json,html}\" \"*.{js,ts,yml,json,html}\" \".*.{js,ts,yml,json,html}\" \"!**/package-lock.json\" \"!package-lock.json\" \"!node/vendor/**\"" }, "keywords": [], "license": "MIT", From 97238640e085b4eaa5a18ff2fec0ea4b7bffe88d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Sat, 18 Nov 2023 10:42:28 +0000 Subject: [PATCH 2/3] chore: remove unnecessary directives --- node/vendor/module_graph/module_graph.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/node/vendor/module_graph/module_graph.ts b/node/vendor/module_graph/module_graph.ts index 0285b9b8..9a15f26b 100644 --- a/node/vendor/module_graph/module_graph.ts +++ b/node/vendor/module_graph/module_graph.ts @@ -1,5 +1,3 @@ -/* eslint-disable */ -/* prettier-ignore */ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. import type { MediaType } from './media_type.js' From 4d991ed93e05e0b0091f5fc09c17d5e74a5583e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Bou=C3=A7as?= Date: Sat, 18 Nov 2023 10:43:58 +0000 Subject: [PATCH 3/3] chore: reset formatting --- node/vendor/module_graph/media_type.ts | 2 +- node/vendor/module_graph/module_graph.ts | 101 ++++++++++++----------- 2 files changed, 53 insertions(+), 50 deletions(-) diff --git a/node/vendor/module_graph/media_type.ts b/node/vendor/module_graph/media_type.ts index 2789280d..d0b48279 100644 --- a/node/vendor/module_graph/media_type.ts +++ b/node/vendor/module_graph/media_type.ts @@ -17,4 +17,4 @@ export enum MediaType { TsBuildInfo = "TsBuildInfo", SourceMap = "SourceMap", Unknown = "Unknown", -} +} \ No newline at end of file diff --git a/node/vendor/module_graph/module_graph.ts b/node/vendor/module_graph/module_graph.ts index 9a15f26b..27b531c2 100644 --- a/node/vendor/module_graph/module_graph.ts +++ b/node/vendor/module_graph/module_graph.ts @@ -1,6 +1,6 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. -import type { MediaType } from './media_type.js' +import type { MediaType } from "./media_type.ts"; /** Additional meta data that is used to enrich the output of the module * graph. */ @@ -8,87 +8,87 @@ export interface CacheInfo { /** The string path to where the local version of the content is located. For * non `file:` URLs, this is the location of the cached content, otherwise it * is the absolute path to the local file. */ - local?: string + local?: string; /** The string path to where a transpiled version of the source content is * located, if any. */ - emit?: string + emit?: string; /** The string path to where an external source map of the transpiled source * content is located, if any. */ - map?: string + map?: string; } export interface TypesDependency { /** The string URL to the type information for the module. */ - types: string + types: string; /** An optional range which indicates the source of the dependency. */ - source?: Range + source?: Range; } export interface LoadResponseModule { /** A module with code has been loaded. */ - kind: 'module' + kind: "module"; /** The string URL of the resource. If there were redirects, the final * specifier should be set here, otherwise the requested specifier. */ - specifier: string + specifier: string; /** For remote resources, a record of headers should be set, where the key's * have been normalized to be lower case values. */ - headers?: Record + headers?: Record; /** The string value of the loaded resources. */ - content: string + content: string; } export interface LoadResponseExternal { /** The loaded module is either _external_ or _built-in_ to the runtime. */ - kind: 'external' + kind: "external"; /** The strung URL of the resource. If there were redirects, the final * specifier should be set here, otherwise the requested specifier. */ - specifier: string + specifier: string; } -export type LoadResponse = LoadResponseModule | LoadResponseExternal +export type LoadResponse = LoadResponseModule | LoadResponseExternal; export interface PositionJson { /** The line number of a position within a source file. The number is a zero * based index. */ - line: number + line: number; /** The character number of a position within a source file. The number is a * zero based index. */ - character: number + character: number; } export interface Range { /** A string URL representing a source of a dependency. */ - specifier: string + specifier: string; /** The start location of a range of text in a source file. */ - start?: PositionJson + start?: PositionJson; /** The end location of a range of text in a source file. */ - end?: PositionJson + end?: PositionJson; } export interface RangeJson { /** The start location of a range of text in a source file. */ - start: PositionJson + start: PositionJson; /** The end location of a range of text in a source file. */ - end: PositionJson + end: PositionJson; } export interface ResolvedDependency { /** The fully resolved string URL of the dependency, which should be * resolvable in the module graph. If there was an error, `error` will be set * and this will be undefined. */ - specifier?: string + specifier?: string; /** Any error encountered when trying to resolved the specifier. If this is * defined, `specifier` will be undefined. */ - error?: string + error?: string; /** The range within the source code where the specifier was identified. */ - span: RangeJson + span: RangeJson; } export interface TypesDependencyJson { /** The string specifier that was used for the dependency. */ - specifier: string + specifier: string; /** An object pointing to the resolved dependency. */ - dependency: ResolvedDependency + dependency: ResolvedDependency; } /** The kind of module. @@ -99,52 +99,56 @@ export interface TypesDependencyJson { * Dependency analysis is not performed for asserted or Script modules * currently. Synthetic modules were injected into the graph with their own * dependencies provided. */ -export type ModuleKind = 'asserted' | 'esm' | 'npm' | 'external' +export type ModuleKind = + | "asserted" + | "esm" + | "npm" + | "external"; export interface DependencyJson { /** The string specifier that was used for the dependency. */ - specifier: string + specifier: string; /** An object pointing to the resolved _code_ dependency. */ - code?: ResolvedDependency + code?: ResolvedDependency; /** An object pointing to the resolved _type_ dependency of a module. This is * populated when the `@deno-types` directive was used to supply a type * definition file for a dependency. */ - type?: ResolvedDependency + type?: ResolvedDependency; /** A flag indicating if the dependency was dynamic. (e.g. * `await import("mod.ts")`) */ - isDynamic?: true - assertionType?: string + isDynamic?: true; + assertionType?: string; } // todo(dsherret): split this up into separate types based on the "kind" export interface ModuleJson extends CacheInfo { /** The string URL of the module. */ - specifier: string + specifier: string; /** Any error encountered when attempting to load the module. */ - error?: string + error?: string; /** The module kind that was determined when the module was resolved. This is * used by loaders to indicate how a module needs to be loaded at runtime. */ - kind?: ModuleKind + kind?: ModuleKind; /** An array of dependencies that were identified in the module. */ - dependencies?: DependencyJson[] + dependencies?: DependencyJson[]; /** If the module had a types dependency, the information about that * dependency. */ - typesDependency?: TypesDependencyJson + typesDependency?: TypesDependencyJson; /** The resolved media type of the module, which determines how Deno will * handle the module. */ - mediaType?: MediaType + mediaType?: MediaType; /** The size of the source content of the module in bytes. */ - size?: number + size?: number; } export interface GraphImportJson { /** The referrer (URL string) that was used as a base when resolving the * imports added to the graph. */ - referrer: string + referrer: string; /** An array of resolved dependencies which were imported using the * referrer. */ - dependencies?: DependencyJson[] + dependencies?: DependencyJson[]; } /** The plain-object representation of a module graph that is suitable for @@ -152,28 +156,27 @@ export interface GraphImportJson { export interface ModuleGraphJson { /** The module specifiers (URL string) of the _roots_ of the module graph of * which the module graph was built for. */ - roots: string[] + roots: string[]; /** An array of modules that are part of the module graph. */ - modules: ModuleJson[] + modules: ModuleJson[]; /** External imports that were added to the graph when it was being built. * The key is the referrer which was used as a base to resolve the * dependency. The value is the resolved dependency. */ - imports?: GraphImportJson[] + imports?: GraphImportJson[]; /** A record/map of any redirects encountered when resolving modules. The * key was the requested module specifier and the value is the redirected * module specifier. */ - redirects: Record + redirects: Record; } export interface Dependency { /** An object pointing to the resolved _code_ dependency. */ - code?: ResolvedDependency + code?: ResolvedDependency; /** An object pointing to the resolved _type_ dependency of a module. This is * populated when the `@deno-types` directive was used to supply a type * definition file for a dependency. */ - type?: ResolvedDependency + type?: ResolvedDependency; /** A flag indicating if the dependency was dynamic. (e.g. * `await import("mod.ts")`) */ - isDynamic?: true -} -/* eslint-enable */ + isDynamic?: true; +} \ No newline at end of file