Skip to content

Commit 01d79d2

Browse files
committed
Deno varsion for land/x
1 parent 9129538 commit 01d79d2

File tree

5 files changed

+58
-11
lines changed

5 files changed

+58
-11
lines changed

deno/mod.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Plugin } from './../node_modules/esbuild/lib/main.d.ts'
2+
import * as Cache from 'https://deno.land/x/cache/mod.ts'
3+
import { resolve } from 'https://deno.land/x/importmap/mod.ts'
4+
import { join } from 'https://deno.land/std/path/mod.ts'
5+
6+
interface Config {
7+
importmap: { imports: { [key: string]: string } }
8+
directory: string
9+
}
10+
11+
export function cache({ importmap = { imports: {} }, directory }: Config): Plugin {
12+
Cache.configure({ directory })
13+
return {
14+
name: 'deno-cache',
15+
setup(build) {
16+
build.onResolve({ filter: /.*/ }, async (args) => {
17+
const resolvedPath = resolve(args.path, importmap)
18+
if (resolvedPath.startsWith('http')) {
19+
return {
20+
path: resolvedPath,
21+
namespace: 'deno-cache',
22+
}
23+
}
24+
if (args.namespace === 'deno-cache') {
25+
return {
26+
path: new URL(resolvedPath, args.importer).toString(),
27+
namespace: 'deno-cache',
28+
}
29+
}
30+
return { path: join(args.resolveDir, resolvedPath) }
31+
})
32+
build.onLoad({ filter: /.*/, namespace: 'deno-cache' }, async (args) => {
33+
const file = await Cache.cache(args.path, undefined, 'deps')
34+
const contents = await Deno.readTextFile(file.path)
35+
return { contents }
36+
})
37+
},
38+
}
39+
}

deno/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "deno.enable": true }

index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
import { Plugin } from './node_modules/esbuild/lib/main.d.ts'
12
import * as DenoCache from 'deno-cache'
23
import { readFile } from 'fs/promises'
34
import { resolve } from 'deno-importmap'
45
import { join } from 'path'
56

6-
export function cache({ importmap = { imports: {} }, directory }) {
7+
interface Config {
8+
importmap: { imports: { [key: string]: string } }
9+
directory: string
10+
}
11+
12+
export function cache({ importmap = { imports: {} }, directory }: Config): Plugin {
713
DenoCache.configure({ directory })
814
return {
915
name: 'deno-cache',

package-lock.json

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"homepage": "https://github.com/dalcib/esbuild-plugin-cache#readme",
3131
"dependencies": {
3232
"deno-cache": "^0.2.12",
33-
"deno-importmap": "^0.1.5",
33+
"deno-importmap": "^0.1.6",
3434
"esbuild": "^0.8.32"
3535
}
3636
}

0 commit comments

Comments
 (0)