-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: check integrity with Deno lockfiles (#4)
* feat: the one with integrity checks * docs: add integrity PR link to changelog * chore: set config defaults at the root
- Loading branch information
1 parent
b5a7f06
commit c92e93a
Showing
14 changed files
with
218 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## Unreleased | ||
|
||
### Added | ||
|
||
- Source map support in [denofn/denopack/pull/2](https://github.com/denofn/denopack/pull/2) | ||
- Lockfile integrity checking in [denofn/denopack/pull/4](https://github.com/denofn/denopack/pull/4) | ||
|
||
### Changed | ||
|
||
- Hooks now take one configuration object as parameter where needed in [denofn/denopack/pull/4](https://github.com/denofn/denopack/pull/4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,42 @@ | ||
import { Plugin } from "../../deps.ts"; | ||
import { path, Plugin } from "../../deps.ts"; | ||
import { buildCacheUrl } from "../../util/buildCacheUrl.ts"; | ||
import { checkIntegrity } from "../../util/checkIntegrity.ts"; | ||
import { isFile } from "../../util/isFile.ts"; | ||
import { isHttpUrl } from "../../util/isHttpUrl.ts"; | ||
|
||
type Opts = { | ||
export type Opts = { | ||
lazy?: boolean; | ||
cacheOnly?: boolean; | ||
lockFile?: string; | ||
}; | ||
|
||
async function cacheLoader( | ||
id: string, | ||
opts: Opts, | ||
lockFile: Record<string, string> | undefined | ||
): Promise<string | null> { | ||
const cacheUrl = buildCacheUrl(id); | ||
const isFileInCache = await isFile(cacheUrl); | ||
|
||
if (opts.cacheOnly && !isFileInCache) throw new Error(`Cannot find ${id} in Deno cache`); | ||
if (!opts.lazy && !isFileInCache) return null; | ||
|
||
const code = await Deno.readTextFile(cacheUrl); | ||
if (lockFile) checkIntegrity(lockFile, id, code); | ||
|
||
return code; | ||
} | ||
|
||
export function pluginCacheLoader(opts: Opts = {}): Plugin { | ||
const lockFile: Record<string, string> | undefined = opts.lockFile | ||
? JSON.parse(Deno.readTextFileSync(path.resolve(opts.lockFile))) | ||
: undefined; | ||
|
||
return { | ||
name: "denopack-plugin-cacheLoader", | ||
async load(id) { | ||
if (!isHttpUrl(id)) return null; | ||
|
||
const cacheUrl = buildCacheUrl(id); | ||
|
||
if (opts.lazy || (await isFile(cacheUrl))) { | ||
const code = await Deno.readTextFile(cacheUrl); | ||
return code; | ||
} | ||
|
||
return null; | ||
return cacheLoader(id, opts, lockFile); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,29 @@ | ||
import { Plugin } from "../../deps.ts"; | ||
import { path, Plugin } from "../../deps.ts"; | ||
import { checkIntegrity } from "../../util/checkIntegrity.ts"; | ||
import { isHttpUrl } from "../../util/isHttpUrl.ts"; | ||
|
||
export function pluginFileLoader(): Plugin { | ||
export type Opts = { | ||
lockFile?: string; | ||
}; | ||
|
||
export function pluginFileLoader(opts: Opts = {}): Plugin { | ||
const lockFile: Record<string, string> | undefined = opts.lockFile | ||
? JSON.parse(Deno.readTextFileSync(path.resolve(opts.lockFile))) | ||
: undefined; | ||
|
||
return { | ||
name: "denopack-plugin-fileLoader", | ||
async load(id) { | ||
if (isHttpUrl(id)) { | ||
const response = await fetch(id); | ||
return response.text(); | ||
} else { | ||
if (!isHttpUrl(id)) { | ||
return Deno.readTextFile(id); | ||
} | ||
|
||
const response = await fetch(id); | ||
const code = await response.text(); | ||
|
||
if (lockFile) checkIntegrity(lockFile, id, code); | ||
|
||
return code; | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,79 @@ | ||
import { pluginCacheLoader } from "./cacheLoader/mod.ts"; | ||
import { pluginFileLoader } from "./fileLoader/mod.ts"; | ||
import { Opts as CacheLoaderOptions, pluginCacheLoader } from "./cacheLoader/mod.ts"; | ||
import { Opts as FileLoaderOptions, pluginFileLoader } from "./fileLoader/mod.ts"; | ||
import { pluginImportResolver } from "./importResolver/mod.ts"; | ||
import { pluginTypescriptCompile } from "./typescriptCompile/mod.ts"; | ||
import { pluginTypescriptTransform } from "./typescriptTransform/mod.ts"; | ||
|
||
export const useAlwaysFetch = (opts: Deno.CompilerOptions = {}) => [ | ||
pluginImportResolver(), | ||
pluginFileLoader(), | ||
pluginTypescriptTransform(opts), | ||
]; | ||
const useLoadAndTransform = ({ | ||
fileLoaderOptions, | ||
compilerOptions, | ||
}: { | ||
compilerOptions?: Deno.CompilerOptions; | ||
fileLoaderOptions?: FileLoaderOptions; | ||
}) => [pluginFileLoader(fileLoaderOptions), pluginTypescriptTransform(compilerOptions)]; | ||
|
||
export const useCache = (opts: Deno.CompilerOptions = {}) => [ | ||
pluginImportResolver(), | ||
pluginCacheLoader(), | ||
pluginFileLoader(), | ||
pluginTypescriptTransform(opts), | ||
]; | ||
export const useAlwaysFetch = ( | ||
opts: { | ||
compilerOptions?: Deno.CompilerOptions; | ||
fileLoaderOptions?: FileLoaderOptions; | ||
} = {} | ||
) => [pluginImportResolver(), ...useLoadAndTransform(opts)]; | ||
|
||
export const useCacheLazy = (opts: Deno.CompilerOptions = {}) => [ | ||
export const useCache = ( | ||
opts: { | ||
cacheLoaderOptions?: CacheLoaderOptions; | ||
compilerOptions?: Deno.CompilerOptions; | ||
fileLoaderOptions?: FileLoaderOptions; | ||
} = {} | ||
) => [ | ||
pluginImportResolver(), | ||
pluginCacheLoader({ lazy: true }), | ||
pluginFileLoader(), | ||
pluginTypescriptTransform(opts), | ||
pluginCacheLoader(opts.cacheLoaderOptions), | ||
...useLoadAndTransform({ | ||
compilerOptions: opts.compilerOptions, | ||
fileLoaderOptions: opts.fileLoaderOptions, | ||
}), | ||
]; | ||
|
||
export const useCompile = (opts: Deno.CompilerOptions = {}) => [ | ||
pluginTypescriptCompile({ useAsLoader: false, compilerOptions: opts }), | ||
pluginFileLoader(), | ||
]; | ||
export const useCacheLazy = ( | ||
opts: { | ||
fileLoaderOptions?: FileLoaderOptions; | ||
cacheLoaderOptions?: CacheLoaderOptions; | ||
compilerOptions?: Deno.CompilerOptions; | ||
} = {} | ||
) => | ||
useCache({ | ||
cacheLoaderOptions: { ...opts.cacheLoaderOptions, lazy: true }, | ||
compilerOptions: opts.compilerOptions, | ||
fileLoaderOptions: opts.fileLoaderOptions, | ||
}); | ||
|
||
export const useCacheOnly = ( | ||
opts: { | ||
fileLoaderOptions?: FileLoaderOptions; | ||
cacheLoaderOptions?: CacheLoaderOptions; | ||
compilerOptions?: Deno.CompilerOptions; | ||
} = {} | ||
) => | ||
useCache({ | ||
fileLoaderOptions: opts.fileLoaderOptions, | ||
cacheLoaderOptions: { ...opts.cacheLoaderOptions, cacheOnly: true }, | ||
compilerOptions: opts.compilerOptions, | ||
}); | ||
|
||
export const useCompileAsLoader = (opts: Deno.CompilerOptions = {}) => [ | ||
pluginTypescriptCompile({ useAsLoader: true, compilerOptions: opts }), | ||
export const useCompile = ( | ||
opts: { | ||
cacheLoaderOptions?: CacheLoaderOptions; | ||
compilerOptions?: Deno.CompilerOptions; | ||
fileLoaderOptions?: FileLoaderOptions; | ||
} = {} | ||
) => [ | ||
pluginTypescriptCompile({ useAsLoader: false, compilerOptions: opts.compilerOptions }), | ||
pluginCacheLoader(opts.cacheLoaderOptions), | ||
pluginFileLoader(opts.fileLoaderOptions), | ||
]; | ||
|
||
export const useCompileAsLoader = ( | ||
opts: { | ||
compilerOptions?: Deno.CompilerOptions; | ||
} = {} | ||
) => [pluginTypescriptCompile({ useAsLoader: true, compilerOptions: opts.compilerOptions })]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.