-
Notifications
You must be signed in to change notification settings - Fork 47
/
mod.ts
89 lines (83 loc) · 3.16 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import type * as esbuild from "./src/esbuild_types.ts";
import {
denoResolverPlugin,
type DenoResolverPluginOptions,
} from "./src/plugin_deno_resolver.ts";
export { denoResolverPlugin, type DenoResolverPluginOptions };
import {
DEFAULT_LOADER,
denoLoaderPlugin,
type DenoLoaderPluginOptions,
} from "./src/plugin_deno_loader.ts";
export { DEFAULT_LOADER, denoLoaderPlugin, type DenoLoaderPluginOptions };
export {
type EsbuildResolution,
esbuildResolutionToURL,
urlToEsbuildResolution,
} from "./src/shared.ts";
/** Options for the {@link denoPlugins} function. */
export interface DenoPluginsOptions {
/**
* Specify which loader to use. By default this will use the `native` loader,
* unless the `--allow-run` permission has not been given.
*
* See {@link denoLoaderPlugin} for more information on the different loaders.
*/
loader?: "native" | "portable";
/**
* Specify the path to a deno.json config file to use. This is equivalent to
* the `--config` flag to the Deno executable. This path must be absolute.
*
* If not specified, the plugin will attempt to find the nearest deno.json and
* use that. If the deno.json is part of a workspace, the plugin will
* automatically find the workspace root.
*/
configPath?: string;
/**
* Specify a URL to an import map file to use when resolving import
* specifiers. This is equivalent to the `--import-map` flag to the Deno
* executable. This URL may be remote or a local file URL.
*
* If this option is not specified, the deno.json config file is consulted to
* determine what import map to use, if any.
*/
importMapURL?: string;
/**
* Specify the path to a deno.lock file to use. This is equivalent to the
* `--lock` flag to the Deno executable. This path must be absolute.
*
* If this option is not specified, the deno.json config file is consulted to
* determine what lock file to use, if any.
*
* A lockfile must be present to resolve `jsr:` specifiers with the `portable`
* loader. When using the `native` loader, a lockfile is not required, but to
* ensure dependencies are de-duplicated correctly, it is recommended to use a
* lockfile.
*/
lockPath?: string;
/**
* Specify how the loader should handle NPM packages. By default and if this
* option is set to `none`, the loader will use the global cache to resolve
* NPM packages. If this option is set to `manual`, the loader will use a
* manually managed `node_modules` directory. If this option is set to `auto`,
* the loader will use a local `node_modules` directory.
*
* If this option is not specified, the deno.json config file is consulted to
* determine which mode to use.
*
* This option is ignored when using the `portable` loader, as the portable
* loader always uses a manual `node_modules` directory (equivalent of
* `nodeModulesDir: "manual"`).
*/
nodeModulesDir?: "auto" | "manual" | "none";
}
/**
* A convenience function to enable both the Deno resolver plugin, and Deno
* loader plugin.
*/
export function denoPlugins(opts: DenoPluginsOptions = {}): esbuild.Plugin[] {
return [
denoResolverPlugin(opts),
denoLoaderPlugin(opts),
];
}