UNPKG

5.18 kBTypeScriptView Raw
1/// <reference types="node" />
2import { SkypackSDK } from '../vendor/types/skypack';
3import { ImportMap, LockfileManifest, PackageSource, SnowpackConfig } from './types';
4export declare const GLOBAL_CACHE_DIR: any;
5export declare const LOCKFILE_NAME = "snowpack.deps.json";
6export declare const NATIVE_REQUIRE: any;
7export declare const remotePackageSDK: SkypackSDK;
8export declare const BUILD_CACHE: string;
9export declare const HTML_JS_REGEX: RegExp;
10export declare const HTML_STYLE_REGEX: RegExp;
11export declare const CSS_REGEX: RegExp;
12export declare const SVELTE_VUE_REGEX: RegExp;
13/**
14 * Like rimraf, but will fail if "dir" is outside of your configured build output directory.
15 */
16export declare function deleteFromBuildSafe(dir: string, config: SnowpackConfig): void;
17/** Read file from disk; return a string if it’s a code file */
18export declare function readFile(filepath: URL): Promise<string | Buffer>;
19export declare function readLockfile(cwd: string): Promise<LockfileManifest | null>;
20export declare function convertLockfileToSkypackImportMap(origin: string, lockfile: LockfileManifest): ImportMap;
21export declare function convertSkypackImportMapToLockfile(dependencies: Record<string, string>, importMap: ImportMap): LockfileManifest;
22export declare function writeLockfile(loc: string, importMap: LockfileManifest): Promise<void>;
23export declare function isTruthy<T>(item: T | false | null | undefined): item is T;
24export declare function getPackageSource(source: 'remote' | 'local'): PackageSource;
25/**
26 * Returns true if fsevents exists. When Snowpack is bundled, automatic fsevents
27 * detection fails for many libraries. This function helps add back support.
28 */
29export declare function isFsEventsEnabled(): boolean;
30/** Get the package name + an entrypoint within that package (if given). */
31export declare function parsePackageImportSpecifier(imp: string): [string, string | null];
32/**
33 * Given a package name, look for that package's package.json manifest.
34 * Return both the manifest location (if believed to exist) and the
35 * manifest itself (if found).
36 *
37 * NOTE: You used to be able to require() a package.json file directly,
38 * but now with export map support in Node v13 that's no longer possible.
39 */
40export declare function resolveDependencyManifest(dep: string, cwd: string): [string | null, any | null];
41/**
42 * If Rollup erred parsing a particular file, show suggestions based on its
43 * file extension (note: lowercase is fine).
44 */
45export declare const MISSING_PLUGIN_SUGGESTIONS: {
46 [ext: string]: string;
47};
48export declare function openInBrowser(protocol: string, hostname: string, port: number, browser: string): Promise<void>;
49export declare function checkLockfileHash(dir: string): Promise<boolean>;
50export declare function updateLockfileHash(dir: string): Promise<void>;
51export declare function clearCache(): Promise<[void, void, void]>;
52/**
53 * For the given import specifier, return an alias entry if one is matched.
54 */
55export declare function findMatchingAliasEntry(config: SnowpackConfig, spec: string): {
56 from: string;
57 to: string;
58 type: 'package' | 'path' | 'url';
59} | undefined;
60/**
61 * Get the most specific file extension match possible.
62 */
63export declare function getExtensionMatch(fileName: string, extensionMap: Record<string, string[]>): [string, string[]] | undefined;
64export declare function isRemoteUrl(val: string): boolean;
65/**
66 * Sanitizes npm packages that end in .js (e.g `tippy.js` -> `tippyjs`).
67 * This is necessary because Snowpack can’t create both a file and directory
68 * that end in .js.
69 */
70export declare function sanitizePackageName(filepath: string): string;
71/** CSS sourceMappingURL */
72export declare function cssSourceMappingURL(code: string, sourceMappingURL: string): string;
73/** JS sourceMappingURL */
74export declare function jsSourceMappingURL(code: string, sourceMappingURL: string): string;
75/** URL relative */
76export declare function relativeURL(path1: string, path2: string): string;
77/** Append HTML before closing </head> tag */
78export declare function appendHtmlToHead(doc: string, htmlToAdd: string): string;
79export declare function isJavaScript(pathname: string): boolean;
80export declare function getExtension(str: string): string;
81export declare function hasExtension(str: string, ext: string): boolean;
82export declare function replaceExtension(fileName: string, oldExt: string, newExt: string): string;
83export declare function addExtension(fileName: string, newExt: string): string;
84export declare function removeExtension(fileName: string, oldExt: string): string;
85/** Add / to beginning of string (but don’t double-up) */
86export declare function addLeadingSlash(path: string): string;
87/** Add / to the end of string (but don’t double-up) */
88export declare function addTrailingSlash(path: string): string;
89/** Remove \ and / from beginning of string */
90export declare function removeLeadingSlash(path: string): string;
91/** Remove \ and / from end of string */
92export declare function removeTrailingSlash(path: string): string;
93export declare const HMR_CLIENT_CODE: string;
94export declare const HMR_OVERLAY_CODE: string;
95export declare const INIT_TEMPLATE_FILE: string;