init
This commit is contained in:
commit
42ef2f9674
468 files changed
+645161
No files matched your search
+570
@@ -0,0 +1,570 @@
|
||||
import { createRequire } from "module";
|
||||
import { basename, dirname, normalize, relative, resolve, sep } from "path";
|
||||
import * as nativeFs from "fs";
|
||||
|
||||
//#region rolldown:runtime
|
||||
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
||||
|
||||
//#endregion
|
||||
//#region src/utils.ts
|
||||
function cleanPath(path) {
|
||||
let normalized = normalize(path);
|
||||
if (normalized.length > 1 && normalized[normalized.length - 1] === sep) normalized = normalized.substring(0, normalized.length - 1);
|
||||
return normalized;
|
||||
}
|
||||
const SLASHES_REGEX = /[\\/]/g;
|
||||
function convertSlashes(path, separator) {
|
||||
return path.replace(SLASHES_REGEX, separator);
|
||||
}
|
||||
const WINDOWS_ROOT_DIR_REGEX = /^[a-z]:[\\/]$/i;
|
||||
function isRootDirectory(path) {
|
||||
return path === "/" || WINDOWS_ROOT_DIR_REGEX.test(path);
|
||||
}
|
||||
function normalizePath(path, options) {
|
||||
const { resolvePaths, normalizePath: normalizePath$1, pathSeparator } = options;
|
||||
const pathNeedsCleaning = process.platform === "win32" && path.includes("/") || path.startsWith(".");
|
||||
if (resolvePaths) path = resolve(path);
|
||||
if (normalizePath$1 || pathNeedsCleaning) path = cleanPath(path);
|
||||
if (path === ".") return "";
|
||||
const needsSeperator = path[path.length - 1] !== pathSeparator;
|
||||
return convertSlashes(needsSeperator ? path + pathSeparator : path, pathSeparator);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/join-path.ts
|
||||
function joinPathWithBasePath(filename, directoryPath) {
|
||||
return directoryPath + filename;
|
||||
}
|
||||
function joinPathWithRelativePath(root, options) {
|
||||
return function(filename, directoryPath) {
|
||||
const sameRoot = directoryPath.startsWith(root);
|
||||
if (sameRoot) return directoryPath.slice(root.length) + filename;
|
||||
else return convertSlashes(relative(root, directoryPath), options.pathSeparator) + options.pathSeparator + filename;
|
||||
};
|
||||
}
|
||||
function joinPath(filename) {
|
||||
return filename;
|
||||
}
|
||||
function joinDirectoryPath(filename, directoryPath, separator) {
|
||||
return directoryPath + filename + separator;
|
||||
}
|
||||
function build$7(root, options) {
|
||||
const { relativePaths, includeBasePath } = options;
|
||||
return relativePaths && root ? joinPathWithRelativePath(root, options) : includeBasePath ? joinPathWithBasePath : joinPath;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/push-directory.ts
|
||||
function pushDirectoryWithRelativePath(root) {
|
||||
return function(directoryPath, paths) {
|
||||
paths.push(directoryPath.substring(root.length) || ".");
|
||||
};
|
||||
}
|
||||
function pushDirectoryFilterWithRelativePath(root) {
|
||||
return function(directoryPath, paths, filters) {
|
||||
const relativePath = directoryPath.substring(root.length) || ".";
|
||||
if (filters.every((filter) => filter(relativePath, true))) paths.push(relativePath);
|
||||
};
|
||||
}
|
||||
const pushDirectory = (directoryPath, paths) => {
|
||||
paths.push(directoryPath || ".");
|
||||
};
|
||||
const pushDirectoryFilter = (directoryPath, paths, filters) => {
|
||||
const path = directoryPath || ".";
|
||||
if (filters.every((filter) => filter(path, true))) paths.push(path);
|
||||
};
|
||||
const empty$2 = () => {};
|
||||
function build$6(root, options) {
|
||||
const { includeDirs, filters, relativePaths } = options;
|
||||
if (!includeDirs) return empty$2;
|
||||
if (relativePaths) return filters && filters.length ? pushDirectoryFilterWithRelativePath(root) : pushDirectoryWithRelativePath(root);
|
||||
return filters && filters.length ? pushDirectoryFilter : pushDirectory;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/push-file.ts
|
||||
const pushFileFilterAndCount = (filename, _paths, counts, filters) => {
|
||||
if (filters.every((filter) => filter(filename, false))) counts.files++;
|
||||
};
|
||||
const pushFileFilter = (filename, paths, _counts, filters) => {
|
||||
if (filters.every((filter) => filter(filename, false))) paths.push(filename);
|
||||
};
|
||||
const pushFileCount = (_filename, _paths, counts, _filters) => {
|
||||
counts.files++;
|
||||
};
|
||||
const pushFile = (filename, paths) => {
|
||||
paths.push(filename);
|
||||
};
|
||||
const empty$1 = () => {};
|
||||
function build$5(options) {
|
||||
const { excludeFiles, filters, onlyCounts } = options;
|
||||
if (excludeFiles) return empty$1;
|
||||
if (filters && filters.length) return onlyCounts ? pushFileFilterAndCount : pushFileFilter;
|
||||
else if (onlyCounts) return pushFileCount;
|
||||
else return pushFile;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/get-array.ts
|
||||
const getArray = (paths) => {
|
||||
return paths;
|
||||
};
|
||||
const getArrayGroup = () => {
|
||||
return [""].slice(0, 0);
|
||||
};
|
||||
function build$4(options) {
|
||||
return options.group ? getArrayGroup : getArray;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/group-files.ts
|
||||
const groupFiles = (groups, directory, files) => {
|
||||
groups.push({
|
||||
directory,
|
||||
files,
|
||||
dir: directory
|
||||
});
|
||||
};
|
||||
const empty = () => {};
|
||||
function build$3(options) {
|
||||
return options.group ? groupFiles : empty;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/resolve-symlink.ts
|
||||
const resolveSymlinksAsync = function(path, state, callback$1) {
|
||||
const { queue, fs, options: { suppressErrors } } = state;
|
||||
queue.enqueue();
|
||||
fs.realpath(path, (error, resolvedPath) => {
|
||||
if (error) return queue.dequeue(suppressErrors ? null : error, state);
|
||||
fs.stat(resolvedPath, (error$1, stat) => {
|
||||
if (error$1) return queue.dequeue(suppressErrors ? null : error$1, state);
|
||||
if (stat.isDirectory() && isRecursive(path, resolvedPath, state)) return queue.dequeue(null, state);
|
||||
callback$1(stat, resolvedPath);
|
||||
queue.dequeue(null, state);
|
||||
});
|
||||
});
|
||||
};
|
||||
const resolveSymlinks = function(path, state, callback$1) {
|
||||
const { queue, fs, options: { suppressErrors } } = state;
|
||||
queue.enqueue();
|
||||
try {
|
||||
const resolvedPath = fs.realpathSync(path);
|
||||
const stat = fs.statSync(resolvedPath);
|
||||
if (stat.isDirectory() && isRecursive(path, resolvedPath, state)) return;
|
||||
callback$1(stat, resolvedPath);
|
||||
} catch (e) {
|
||||
if (!suppressErrors) throw e;
|
||||
}
|
||||
};
|
||||
function build$2(options, isSynchronous) {
|
||||
if (!options.resolveSymlinks || options.excludeSymlinks) return null;
|
||||
return isSynchronous ? resolveSymlinks : resolveSymlinksAsync;
|
||||
}
|
||||
function isRecursive(path, resolved, state) {
|
||||
if (state.options.useRealPaths) return isRecursiveUsingRealPaths(resolved, state);
|
||||
let parent = dirname(path);
|
||||
let depth = 1;
|
||||
while (parent !== state.root && depth < 2) {
|
||||
const resolvedPath = state.symlinks.get(parent);
|
||||
const isSameRoot = !!resolvedPath && (resolvedPath === resolved || resolvedPath.startsWith(resolved) || resolved.startsWith(resolvedPath));
|
||||
if (isSameRoot) depth++;
|
||||
else parent = dirname(parent);
|
||||
}
|
||||
state.symlinks.set(path, resolved);
|
||||
return depth > 1;
|
||||
}
|
||||
function isRecursiveUsingRealPaths(resolved, state) {
|
||||
return state.visited.includes(resolved + state.options.pathSeparator);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/invoke-callback.ts
|
||||
const onlyCountsSync = (state) => {
|
||||
return state.counts;
|
||||
};
|
||||
const groupsSync = (state) => {
|
||||
return state.groups;
|
||||
};
|
||||
const defaultSync = (state) => {
|
||||
return state.paths;
|
||||
};
|
||||
const limitFilesSync = (state) => {
|
||||
return state.paths.slice(0, state.options.maxFiles);
|
||||
};
|
||||
const onlyCountsAsync = (state, error, callback$1) => {
|
||||
report(error, callback$1, state.counts, state.options.suppressErrors);
|
||||
return null;
|
||||
};
|
||||
const defaultAsync = (state, error, callback$1) => {
|
||||
report(error, callback$1, state.paths, state.options.suppressErrors);
|
||||
return null;
|
||||
};
|
||||
const limitFilesAsync = (state, error, callback$1) => {
|
||||
report(error, callback$1, state.paths.slice(0, state.options.maxFiles), state.options.suppressErrors);
|
||||
return null;
|
||||
};
|
||||
const groupsAsync = (state, error, callback$1) => {
|
||||
report(error, callback$1, state.groups, state.options.suppressErrors);
|
||||
return null;
|
||||
};
|
||||
function report(error, callback$1, output, suppressErrors) {
|
||||
if (error && !suppressErrors) callback$1(error, output);
|
||||
else callback$1(null, output);
|
||||
}
|
||||
function build$1(options, isSynchronous) {
|
||||
const { onlyCounts, group, maxFiles } = options;
|
||||
if (onlyCounts) return isSynchronous ? onlyCountsSync : onlyCountsAsync;
|
||||
else if (group) return isSynchronous ? groupsSync : groupsAsync;
|
||||
else if (maxFiles) return isSynchronous ? limitFilesSync : limitFilesAsync;
|
||||
else return isSynchronous ? defaultSync : defaultAsync;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/functions/walk-directory.ts
|
||||
const readdirOpts = { withFileTypes: true };
|
||||
const walkAsync = (state, crawlPath, directoryPath, currentDepth, callback$1) => {
|
||||
state.queue.enqueue();
|
||||
if (currentDepth < 0) return state.queue.dequeue(null, state);
|
||||
const { fs } = state;
|
||||
state.visited.push(crawlPath);
|
||||
state.counts.directories++;
|
||||
fs.readdir(crawlPath || ".", readdirOpts, (error, entries = []) => {
|
||||
callback$1(entries, directoryPath, currentDepth);
|
||||
state.queue.dequeue(state.options.suppressErrors ? null : error, state);
|
||||
});
|
||||
};
|
||||
const walkSync = (state, crawlPath, directoryPath, currentDepth, callback$1) => {
|
||||
const { fs } = state;
|
||||
if (currentDepth < 0) return;
|
||||
state.visited.push(crawlPath);
|
||||
state.counts.directories++;
|
||||
let entries = [];
|
||||
try {
|
||||
entries = fs.readdirSync(crawlPath || ".", readdirOpts);
|
||||
} catch (e) {
|
||||
if (!state.options.suppressErrors) throw e;
|
||||
}
|
||||
callback$1(entries, directoryPath, currentDepth);
|
||||
};
|
||||
function build(isSynchronous) {
|
||||
return isSynchronous ? walkSync : walkAsync;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/queue.ts
|
||||
/**
|
||||
* This is a custom stateless queue to track concurrent async fs calls.
|
||||
* It increments a counter whenever a call is queued and decrements it
|
||||
* as soon as it completes. When the counter hits 0, it calls onQueueEmpty.
|
||||
*/
|
||||
var Queue = class {
|
||||
count = 0;
|
||||
constructor(onQueueEmpty) {
|
||||
this.onQueueEmpty = onQueueEmpty;
|
||||
}
|
||||
enqueue() {
|
||||
this.count++;
|
||||
return this.count;
|
||||
}
|
||||
dequeue(error, output) {
|
||||
if (this.onQueueEmpty && (--this.count <= 0 || error)) {
|
||||
this.onQueueEmpty(error, output);
|
||||
if (error) {
|
||||
output.controller.abort();
|
||||
this.onQueueEmpty = void 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/api/counter.ts
|
||||
var Counter = class {
|
||||
_files = 0;
|
||||
_directories = 0;
|
||||
set files(num) {
|
||||
this._files = num;
|
||||
}
|
||||
get files() {
|
||||
return this._files;
|
||||
}
|
||||
set directories(num) {
|
||||
this._directories = num;
|
||||
}
|
||||
get directories() {
|
||||
return this._directories;
|
||||
}
|
||||
/**
|
||||
* @deprecated use `directories` instead
|
||||
*/
|
||||
/* c8 ignore next 3 */
|
||||
get dirs() {
|
||||
return this._directories;
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/api/aborter.ts
|
||||
/**
|
||||
* AbortController is not supported on Node 14 so we use this until we can drop
|
||||
* support for Node 14.
|
||||
*/
|
||||
var Aborter = class {
|
||||
aborted = false;
|
||||
abort() {
|
||||
this.aborted = true;
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/api/walker.ts
|
||||
var Walker = class {
|
||||
root;
|
||||
isSynchronous;
|
||||
state;
|
||||
joinPath;
|
||||
pushDirectory;
|
||||
pushFile;
|
||||
getArray;
|
||||
groupFiles;
|
||||
resolveSymlink;
|
||||
walkDirectory;
|
||||
callbackInvoker;
|
||||
constructor(root, options, callback$1) {
|
||||
this.isSynchronous = !callback$1;
|
||||
this.callbackInvoker = build$1(options, this.isSynchronous);
|
||||
this.root = normalizePath(root, options);
|
||||
this.state = {
|
||||
root: isRootDirectory(this.root) ? this.root : this.root.slice(0, -1),
|
||||
paths: [""].slice(0, 0),
|
||||
groups: [],
|
||||
counts: new Counter(),
|
||||
options,
|
||||
queue: new Queue((error, state) => this.callbackInvoker(state, error, callback$1)),
|
||||
symlinks: /* @__PURE__ */ new Map(),
|
||||
visited: [""].slice(0, 0),
|
||||
controller: new Aborter(),
|
||||
fs: options.fs || nativeFs
|
||||
};
|
||||
this.joinPath = build$7(this.root, options);
|
||||
this.pushDirectory = build$6(this.root, options);
|
||||
this.pushFile = build$5(options);
|
||||
this.getArray = build$4(options);
|
||||
this.groupFiles = build$3(options);
|
||||
this.resolveSymlink = build$2(options, this.isSynchronous);
|
||||
this.walkDirectory = build(this.isSynchronous);
|
||||
}
|
||||
start() {
|
||||
this.pushDirectory(this.root, this.state.paths, this.state.options.filters);
|
||||
this.walkDirectory(this.state, this.root, this.root, this.state.options.maxDepth, this.walk);
|
||||
return this.isSynchronous ? this.callbackInvoker(this.state, null) : null;
|
||||
}
|
||||
walk = (entries, directoryPath, depth) => {
|
||||
const { paths, options: { filters, resolveSymlinks: resolveSymlinks$1, excludeSymlinks, exclude, maxFiles, signal, useRealPaths, pathSeparator }, controller } = this.state;
|
||||
if (controller.aborted || signal && signal.aborted || maxFiles && paths.length > maxFiles) return;
|
||||
const files = this.getArray(this.state.paths);
|
||||
for (let i = 0; i < entries.length; ++i) {
|
||||
const entry = entries[i];
|
||||
if (entry.isFile() || entry.isSymbolicLink() && !resolveSymlinks$1 && !excludeSymlinks) {
|
||||
const filename = this.joinPath(entry.name, directoryPath);
|
||||
this.pushFile(filename, files, this.state.counts, filters);
|
||||
} else if (entry.isDirectory()) {
|
||||
let path = joinDirectoryPath(entry.name, directoryPath, this.state.options.pathSeparator);
|
||||
if (exclude && exclude(entry.name, path)) continue;
|
||||
this.pushDirectory(path, paths, filters);
|
||||
this.walkDirectory(this.state, path, path, depth - 1, this.walk);
|
||||
} else if (this.resolveSymlink && entry.isSymbolicLink()) {
|
||||
let path = joinPathWithBasePath(entry.name, directoryPath);
|
||||
this.resolveSymlink(path, this.state, (stat, resolvedPath) => {
|
||||
if (stat.isDirectory()) {
|
||||
resolvedPath = normalizePath(resolvedPath, this.state.options);
|
||||
if (exclude && exclude(entry.name, useRealPaths ? resolvedPath : path + pathSeparator)) return;
|
||||
this.walkDirectory(this.state, resolvedPath, useRealPaths ? resolvedPath : path + pathSeparator, depth - 1, this.walk);
|
||||
} else {
|
||||
resolvedPath = useRealPaths ? resolvedPath : path;
|
||||
const filename = basename(resolvedPath);
|
||||
const directoryPath$1 = normalizePath(dirname(resolvedPath), this.state.options);
|
||||
resolvedPath = this.joinPath(filename, directoryPath$1);
|
||||
this.pushFile(resolvedPath, files, this.state.counts, filters);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
this.groupFiles(this.state.groups, directoryPath, files);
|
||||
};
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/api/async.ts
|
||||
function promise(root, options) {
|
||||
return new Promise((resolve$1, reject) => {
|
||||
callback(root, options, (err, output) => {
|
||||
if (err) return reject(err);
|
||||
resolve$1(output);
|
||||
});
|
||||
});
|
||||
}
|
||||
function callback(root, options, callback$1) {
|
||||
let walker = new Walker(root, options, callback$1);
|
||||
walker.start();
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/api/sync.ts
|
||||
function sync(root, options) {
|
||||
const walker = new Walker(root, options);
|
||||
return walker.start();
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/builder/api-builder.ts
|
||||
var APIBuilder = class {
|
||||
constructor(root, options) {
|
||||
this.root = root;
|
||||
this.options = options;
|
||||
}
|
||||
withPromise() {
|
||||
return promise(this.root, this.options);
|
||||
}
|
||||
withCallback(cb) {
|
||||
callback(this.root, this.options, cb);
|
||||
}
|
||||
sync() {
|
||||
return sync(this.root, this.options);
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/builder/index.ts
|
||||
let pm = null;
|
||||
/* c8 ignore next 6 */
|
||||
try {
|
||||
__require.resolve("picomatch");
|
||||
pm = __require("picomatch");
|
||||
} catch {}
|
||||
var Builder = class {
|
||||
globCache = {};
|
||||
options = {
|
||||
maxDepth: Infinity,
|
||||
suppressErrors: true,
|
||||
pathSeparator: sep,
|
||||
filters: []
|
||||
};
|
||||
globFunction;
|
||||
constructor(options) {
|
||||
this.options = {
|
||||
...this.options,
|
||||
...options
|
||||
};
|
||||
this.globFunction = this.options.globFunction;
|
||||
}
|
||||
group() {
|
||||
this.options.group = true;
|
||||
return this;
|
||||
}
|
||||
withPathSeparator(separator) {
|
||||
this.options.pathSeparator = separator;
|
||||
return this;
|
||||
}
|
||||
withBasePath() {
|
||||
this.options.includeBasePath = true;
|
||||
return this;
|
||||
}
|
||||
withRelativePaths() {
|
||||
this.options.relativePaths = true;
|
||||
return this;
|
||||
}
|
||||
withDirs() {
|
||||
this.options.includeDirs = true;
|
||||
return this;
|
||||
}
|
||||
withMaxDepth(depth) {
|
||||
this.options.maxDepth = depth;
|
||||
return this;
|
||||
}
|
||||
withMaxFiles(limit) {
|
||||
this.options.maxFiles = limit;
|
||||
return this;
|
||||
}
|
||||
withFullPaths() {
|
||||
this.options.resolvePaths = true;
|
||||
this.options.includeBasePath = true;
|
||||
return this;
|
||||
}
|
||||
withErrors() {
|
||||
this.options.suppressErrors = false;
|
||||
return this;
|
||||
}
|
||||
withSymlinks({ resolvePaths = true } = {}) {
|
||||
this.options.resolveSymlinks = true;
|
||||
this.options.useRealPaths = resolvePaths;
|
||||
return this.withFullPaths();
|
||||
}
|
||||
withAbortSignal(signal) {
|
||||
this.options.signal = signal;
|
||||
return this;
|
||||
}
|
||||
normalize() {
|
||||
this.options.normalizePath = true;
|
||||
return this;
|
||||
}
|
||||
filter(predicate) {
|
||||
this.options.filters.push(predicate);
|
||||
return this;
|
||||
}
|
||||
onlyDirs() {
|
||||
this.options.excludeFiles = true;
|
||||
this.options.includeDirs = true;
|
||||
return this;
|
||||
}
|
||||
exclude(predicate) {
|
||||
this.options.exclude = predicate;
|
||||
return this;
|
||||
}
|
||||
onlyCounts() {
|
||||
this.options.onlyCounts = true;
|
||||
return this;
|
||||
}
|
||||
crawl(root) {
|
||||
return new APIBuilder(root || ".", this.options);
|
||||
}
|
||||
withGlobFunction(fn) {
|
||||
this.globFunction = fn;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* @deprecated Pass options using the constructor instead:
|
||||
* ```ts
|
||||
* new fdir(options).crawl("/path/to/root");
|
||||
* ```
|
||||
* This method will be removed in v7.0
|
||||
*/
|
||||
/* c8 ignore next 4 */
|
||||
crawlWithOptions(root, options) {
|
||||
this.options = {
|
||||
...this.options,
|
||||
...options
|
||||
};
|
||||
return new APIBuilder(root || ".", this.options);
|
||||
}
|
||||
glob(...patterns) {
|
||||
if (this.globFunction) return this.globWithOptions(patterns);
|
||||
return this.globWithOptions(patterns, ...[{ dot: true }]);
|
||||
}
|
||||
globWithOptions(patterns, ...options) {
|
||||
const globFn = this.globFunction || pm;
|
||||
/* c8 ignore next 5 */
|
||||
if (!globFn) throw new Error("Please specify a glob function to use glob matching.");
|
||||
var isMatch = this.globCache[patterns.join("\0")];
|
||||
if (!isMatch) {
|
||||
isMatch = globFn(patterns, ...options);
|
||||
this.globCache[patterns.join("\0")] = isMatch;
|
||||
}
|
||||
this.options.filters.push((path) => isMatch(path));
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
export { Builder as fdir };
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
|
||||
let { urlAlphabet } = require('./url-alphabet/index.cjs')
|
||||
|
||||
let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
|
||||
|
||||
let customRandom = (alphabet, defaultSize, getRandom) => {
|
||||
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
|
||||
|
||||
|
||||
|
||||
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
|
||||
|
||||
return (size = defaultSize) => {
|
||||
if (size <= 0) return ''
|
||||
let id = ''
|
||||
while (true) {
|
||||
let bytes = getRandom(step)
|
||||
let j = step | 0
|
||||
while (j--) {
|
||||
id += alphabet[bytes[j] & mask] || ''
|
||||
if (id.length === size) return id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let customAlphabet = (alphabet, size = 21) =>
|
||||
customRandom(alphabet, size, random)
|
||||
|
||||
let nanoid = (size = 21) =>
|
||||
crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
|
||||
byte &= 63
|
||||
if (byte < 36) {
|
||||
id += byte.toString(36)
|
||||
} else if (byte < 62) {
|
||||
id += (byte - 26).toString(36).toUpperCase()
|
||||
} else if (byte > 62) {
|
||||
id += '-'
|
||||
} else {
|
||||
id += '_'
|
||||
}
|
||||
return id
|
||||
}, '')
|
||||
|
||||
module.exports = { nanoid, customAlphabet, customRandom, urlAlphabet, random }
|
||||
+572
@@ -0,0 +1,572 @@
|
||||
/*
|
||||
@license
|
||||
Rollup.js v4.63.1
|
||||
Fri, 28 Aug 2026 05:58:50 GMT - commit 78bfef0cb94479566f81012fafa372c84b90bd34
|
||||
|
||||
https://github.com/rollup/rollup
|
||||
|
||||
Released under the MIT License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const promises = require('node:fs/promises');
|
||||
const path = require('node:path');
|
||||
const process$1 = require('node:process');
|
||||
const node_url = require('node:url');
|
||||
const rollup = require('./rollup.js');
|
||||
const parseAst_js = require('./parseAst.js');
|
||||
const getLogFilter_js = require('../getLogFilter.js');
|
||||
|
||||
function batchWarnings(command) {
|
||||
const silent = !!command.silent;
|
||||
const logFilter = generateLogFilter(command);
|
||||
let count = 0;
|
||||
const deferredWarnings = new Map();
|
||||
let warningOccurred = false;
|
||||
const add = (warning) => {
|
||||
count += 1;
|
||||
warningOccurred = true;
|
||||
if (silent)
|
||||
return;
|
||||
if (warning.code in deferredHandlers) {
|
||||
rollup.getOrCreate(deferredWarnings, warning.code, rollup.getNewArray).push(warning);
|
||||
}
|
||||
else if (warning.code in immediateHandlers) {
|
||||
immediateHandlers[warning.code](warning);
|
||||
}
|
||||
else {
|
||||
title(warning.message);
|
||||
defaultBody(warning);
|
||||
}
|
||||
};
|
||||
return {
|
||||
add,
|
||||
get count() {
|
||||
return count;
|
||||
},
|
||||
flush() {
|
||||
if (count === 0 || silent)
|
||||
return;
|
||||
const codes = [...deferredWarnings.keys()].sort((a, b) => deferredWarnings.get(b).length - deferredWarnings.get(a).length);
|
||||
for (const code of codes) {
|
||||
deferredHandlers[code](deferredWarnings.get(code));
|
||||
}
|
||||
deferredWarnings.clear();
|
||||
count = 0;
|
||||
},
|
||||
log(level, log) {
|
||||
if (!logFilter(log))
|
||||
return;
|
||||
switch (level) {
|
||||
case parseAst_js.LOGLEVEL_WARN: {
|
||||
return add(log);
|
||||
}
|
||||
case parseAst_js.LOGLEVEL_DEBUG: {
|
||||
if (!silent) {
|
||||
rollup.stderr(rollup.bold(rollup.pc.blue(log.message)));
|
||||
defaultBody(log);
|
||||
}
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
if (!silent) {
|
||||
rollup.stderr(rollup.bold(rollup.pc.cyan(log.message)));
|
||||
defaultBody(log);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
get warningOccurred() {
|
||||
return warningOccurred;
|
||||
}
|
||||
};
|
||||
}
|
||||
const immediateHandlers = {
|
||||
MISSING_NODE_BUILTINS(warning) {
|
||||
title(`Missing shims for Node.js built-ins`);
|
||||
rollup.stderr(`Creating a browser bundle that depends on ${parseAst_js.printQuotedStringList(warning.ids)}. You might need to include https://github.com/FredKSchott/rollup-plugin-polyfill-node`);
|
||||
},
|
||||
UNKNOWN_OPTION(warning) {
|
||||
title(`You have passed an unrecognized option`);
|
||||
rollup.stderr(warning.message);
|
||||
}
|
||||
};
|
||||
const deferredHandlers = {
|
||||
CIRCULAR_DEPENDENCY(warnings) {
|
||||
title(`Circular dependenc${warnings.length > 1 ? 'ies' : 'y'}`);
|
||||
const displayed = warnings.length > 5 ? warnings.slice(0, 3) : warnings;
|
||||
for (const warning of displayed) {
|
||||
rollup.stderr(warning.ids.map(parseAst_js.relativeId).join(' -> '));
|
||||
}
|
||||
if (warnings.length > displayed.length) {
|
||||
rollup.stderr(`...and ${warnings.length - displayed.length} more`);
|
||||
}
|
||||
},
|
||||
EMPTY_BUNDLE(warnings) {
|
||||
title(`Generated${warnings.length === 1 ? ' an' : ''} empty ${warnings.length > 1 ? 'chunks' : 'chunk'}`);
|
||||
rollup.stderr(parseAst_js.printQuotedStringList(warnings.map(warning => warning.names[0])));
|
||||
},
|
||||
EVAL(warnings) {
|
||||
title('Use of eval is strongly discouraged');
|
||||
info(parseAst_js.getRollupUrl(parseAst_js.URL_AVOIDING_EVAL));
|
||||
showTruncatedWarnings(warnings);
|
||||
},
|
||||
MISSING_EXPORT(warnings) {
|
||||
title('Missing exports');
|
||||
info(parseAst_js.getRollupUrl(parseAst_js.URL_NAME_IS_NOT_EXPORTED));
|
||||
for (const warning of warnings) {
|
||||
rollup.stderr(rollup.bold(parseAst_js.relativeId(warning.id)));
|
||||
rollup.stderr(`${warning.binding} is not exported by ${parseAst_js.relativeId(warning.exporter)}`);
|
||||
rollup.stderr(rollup.gray(warning.frame));
|
||||
}
|
||||
},
|
||||
MISSING_GLOBAL_NAME(warnings) {
|
||||
title(`Missing global variable ${warnings.length > 1 ? 'names' : 'name'}`);
|
||||
info(parseAst_js.getRollupUrl(parseAst_js.URL_OUTPUT_GLOBALS));
|
||||
rollup.stderr(`Use "output.globals" to specify browser global variable names corresponding to external modules:`);
|
||||
for (const warning of warnings) {
|
||||
rollup.stderr(`${rollup.bold(warning.id)} (guessing "${warning.names[0]}")`);
|
||||
}
|
||||
},
|
||||
MIXED_EXPORTS(warnings) {
|
||||
title('Mixing named and default exports');
|
||||
info(parseAst_js.getRollupUrl(parseAst_js.URL_OUTPUT_EXPORTS));
|
||||
rollup.stderr(rollup.bold('The following entry modules are using named and default exports together:'));
|
||||
warnings.sort((a, b) => (a.id < b.id ? -1 : 1));
|
||||
const displayedWarnings = warnings.length > 5 ? warnings.slice(0, 3) : warnings;
|
||||
for (const warning of displayedWarnings) {
|
||||
rollup.stderr(parseAst_js.relativeId(warning.id));
|
||||
}
|
||||
if (displayedWarnings.length < warnings.length) {
|
||||
rollup.stderr(`...and ${warnings.length - displayedWarnings.length} other entry modules`);
|
||||
}
|
||||
rollup.stderr(`\nConsumers of your bundle will have to use chunk.default to access their default export, which may not be what you want. Use \`output.exports: "named"\` to disable this warning.`);
|
||||
},
|
||||
NAMESPACE_CONFLICT(warnings) {
|
||||
title(`Conflicting re-exports`);
|
||||
for (const warning of warnings) {
|
||||
rollup.stderr(`"${rollup.bold(parseAst_js.relativeId(warning.reexporter))}" re-exports "${warning.binding}" from both "${parseAst_js.relativeId(warning.ids[0])}" and "${parseAst_js.relativeId(warning.ids[1])}" (will be ignored).`);
|
||||
}
|
||||
},
|
||||
PLUGIN_WARNING(warnings) {
|
||||
const nestedByPlugin = nest(warnings, 'plugin');
|
||||
for (const { items } of nestedByPlugin) {
|
||||
const nestedByMessage = nest(items, 'message');
|
||||
let lastUrl = '';
|
||||
for (const { key: message, items } of nestedByMessage) {
|
||||
title(message);
|
||||
for (const warning of items) {
|
||||
if (warning.url && warning.url !== lastUrl)
|
||||
info((lastUrl = warning.url));
|
||||
const loc = formatLocation(warning);
|
||||
if (loc) {
|
||||
rollup.stderr(rollup.bold(loc));
|
||||
}
|
||||
if (warning.frame)
|
||||
info(warning.frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
SOURCEMAP_BROKEN(warnings) {
|
||||
title(`Broken sourcemap`);
|
||||
info(parseAst_js.getRollupUrl(parseAst_js.URL_SOURCEMAP_IS_LIKELY_TO_BE_INCORRECT));
|
||||
const plugins = [...new Set(warnings.map(({ plugin }) => plugin).filter(Boolean))];
|
||||
rollup.stderr(`Plugins that transform code (such as ${parseAst_js.printQuotedStringList(plugins)}) should generate accompanying sourcemaps.`);
|
||||
},
|
||||
THIS_IS_UNDEFINED(warnings) {
|
||||
title('"this" has been rewritten to "undefined"');
|
||||
info(parseAst_js.getRollupUrl(parseAst_js.URL_THIS_IS_UNDEFINED));
|
||||
showTruncatedWarnings(warnings);
|
||||
},
|
||||
UNRESOLVED_IMPORT(warnings) {
|
||||
title('Unresolved dependencies');
|
||||
info(parseAst_js.getRollupUrl(parseAst_js.URL_TREATING_MODULE_AS_EXTERNAL_DEPENDENCY));
|
||||
const dependencies = new Map();
|
||||
for (const warning of warnings) {
|
||||
rollup.getOrCreate(dependencies, parseAst_js.relativeId(warning.exporter), rollup.getNewArray).push(parseAst_js.relativeId(warning.id));
|
||||
}
|
||||
for (const [dependency, importers] of dependencies) {
|
||||
rollup.stderr(`${rollup.bold(dependency)} (imported by ${parseAst_js.printQuotedStringList(importers)})`);
|
||||
}
|
||||
},
|
||||
UNUSED_EXTERNAL_IMPORT(warnings) {
|
||||
title('Unused external imports');
|
||||
for (const warning of warnings) {
|
||||
rollup.stderr(warning.names +
|
||||
' imported from external module "' +
|
||||
warning.exporter +
|
||||
'" but never used in ' +
|
||||
parseAst_js.printQuotedStringList(warning.ids.map(parseAst_js.relativeId)) +
|
||||
'.');
|
||||
}
|
||||
}
|
||||
};
|
||||
function defaultBody(log) {
|
||||
if (log.url) {
|
||||
info(log.url);
|
||||
}
|
||||
const loc = formatLocation(log);
|
||||
if (loc) {
|
||||
rollup.stderr(rollup.bold(loc));
|
||||
}
|
||||
if (log.frame)
|
||||
info(log.frame);
|
||||
}
|
||||
function title(string_) {
|
||||
rollup.stderr(rollup.bold(rollup.yellow(`(!) ${string_}`)));
|
||||
}
|
||||
function info(url) {
|
||||
rollup.stderr(rollup.gray(url));
|
||||
}
|
||||
function nest(array, property) {
|
||||
const nested = [];
|
||||
const lookup = new Map();
|
||||
for (const item of array) {
|
||||
const key = item[property];
|
||||
rollup.getOrCreate(lookup, key, () => {
|
||||
const items = {
|
||||
items: [],
|
||||
key
|
||||
};
|
||||
nested.push(items);
|
||||
return items;
|
||||
}).items.push(item);
|
||||
}
|
||||
return nested;
|
||||
}
|
||||
function showTruncatedWarnings(warnings) {
|
||||
const nestedByModule = nest(warnings, 'id');
|
||||
const displayedByModule = nestedByModule.length > 5 ? nestedByModule.slice(0, 3) : nestedByModule;
|
||||
for (const { key: id, items } of displayedByModule) {
|
||||
rollup.stderr(rollup.bold(parseAst_js.relativeId(id)));
|
||||
rollup.stderr(rollup.gray(items[0].frame));
|
||||
if (items.length > 1) {
|
||||
rollup.stderr(`...and ${items.length - 1} other ${items.length > 2 ? 'occurrences' : 'occurrence'}`);
|
||||
}
|
||||
}
|
||||
if (nestedByModule.length > displayedByModule.length) {
|
||||
rollup.stderr(`\n...and ${nestedByModule.length - displayedByModule.length} other files`);
|
||||
}
|
||||
}
|
||||
function generateLogFilter(command) {
|
||||
const filters = rollup.ensureArray(command.filterLogs).flatMap(filter => String(filter).split(','));
|
||||
if (process.env.ROLLUP_FILTER_LOGS) {
|
||||
filters.push(...process.env.ROLLUP_FILTER_LOGS.split(','));
|
||||
}
|
||||
return getLogFilter_js.getLogFilter(filters);
|
||||
}
|
||||
function formatLocation(log) {
|
||||
const id = log.loc?.file || log.id;
|
||||
if (!id)
|
||||
return null;
|
||||
return log.loc ? `${id}:${log.loc.line}:${log.loc.column}` : id;
|
||||
}
|
||||
|
||||
const stdinName = '-';
|
||||
let stdinResult = null;
|
||||
function stdinPlugin(argument) {
|
||||
const suffix = typeof argument == 'string' && argument.length > 0 ? '.' + argument : '';
|
||||
return {
|
||||
load(id) {
|
||||
if (id === stdinName || id.startsWith(stdinName + '.')) {
|
||||
return stdinResult || (stdinResult = readStdin());
|
||||
}
|
||||
},
|
||||
name: 'stdin',
|
||||
resolveId(id) {
|
||||
if (id === stdinName) {
|
||||
return id + suffix;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
function readStdin() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const chunks = [];
|
||||
process$1.stdin.setEncoding('utf8');
|
||||
process$1.stdin
|
||||
.on('data', chunk => chunks.push(chunk))
|
||||
.on('end', () => {
|
||||
const result = chunks.join('');
|
||||
resolve(result);
|
||||
})
|
||||
.on('error', error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function waitForInputPlugin() {
|
||||
return {
|
||||
async buildStart(options) {
|
||||
const inputSpecifiers = Array.isArray(options.input)
|
||||
? options.input
|
||||
: Object.keys(options.input);
|
||||
let lastAwaitedSpecifier = null;
|
||||
checkSpecifiers: while (true) {
|
||||
for (const specifier of inputSpecifiers) {
|
||||
if ((await this.resolve(specifier)) === null) {
|
||||
if (lastAwaitedSpecifier !== specifier) {
|
||||
rollup.stderr(`waiting for input ${rollup.bold(specifier)}...`);
|
||||
lastAwaitedSpecifier = specifier;
|
||||
}
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
continue checkSpecifiers;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
name: 'wait-for-input'
|
||||
};
|
||||
}
|
||||
|
||||
async function addCommandPluginsToInputOptions(inputOptions, command) {
|
||||
if (command.stdin !== false) {
|
||||
inputOptions.plugins.push(stdinPlugin(command.stdin));
|
||||
}
|
||||
if (command.waitForBundleInput === true) {
|
||||
inputOptions.plugins.push(waitForInputPlugin());
|
||||
}
|
||||
await addPluginsFromCommandOption(command.plugin, inputOptions);
|
||||
}
|
||||
async function addPluginsFromCommandOption(commandPlugin, inputOptions) {
|
||||
if (commandPlugin) {
|
||||
const plugins = await rollup.normalizePluginOption(commandPlugin);
|
||||
for (const plugin of plugins) {
|
||||
if (/[={}]/.test(plugin)) {
|
||||
// -p plugin=value
|
||||
// -p "{transform(c,i){...}}"
|
||||
await loadAndRegisterPlugin(inputOptions, plugin);
|
||||
}
|
||||
else {
|
||||
// split out plugins joined by commas
|
||||
// -p node-resolve,commonjs,buble
|
||||
for (const p of plugin.split(',')) {
|
||||
await loadAndRegisterPlugin(inputOptions, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
async function loadAndRegisterPlugin(inputOptions, pluginText) {
|
||||
let plugin = null;
|
||||
let pluginArgument = undefined;
|
||||
if (pluginText[0] === '{') {
|
||||
// -p "{transform(c,i){...}}"
|
||||
plugin = new Function('return ' + pluginText);
|
||||
}
|
||||
else {
|
||||
const match = pluginText.match(/^([\w./:@\\^{|}-]+)(=(.*))?$/);
|
||||
if (match) {
|
||||
// -p plugin
|
||||
// -p plugin=arg
|
||||
pluginText = match[1];
|
||||
pluginArgument = new Function('return ' + match[3])();
|
||||
}
|
||||
else {
|
||||
throw new Error(`Invalid --plugin argument format: ${JSON.stringify(pluginText)}`);
|
||||
}
|
||||
if (!/^\.|^rollup-plugin-|[/@\\]/.test(pluginText)) {
|
||||
// Try using plugin prefix variations first if applicable.
|
||||
// Prefix order is significant - left has higher precedence.
|
||||
for (const prefix of ['@rollup/plugin-', 'rollup-plugin-']) {
|
||||
try {
|
||||
plugin = await requireOrImport(prefix + pluginText);
|
||||
break;
|
||||
}
|
||||
catch {
|
||||
// if this does not work, we try requiring the actual name below
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!plugin) {
|
||||
try {
|
||||
if (pluginText[0] == '.')
|
||||
pluginText = path.resolve(pluginText);
|
||||
// Windows absolute paths must be specified as file:// protocol URL
|
||||
// Note that we do not have coverage for Windows-only code paths
|
||||
else if (/^[A-Za-z]:\\/.test(pluginText)) {
|
||||
pluginText = node_url.pathToFileURL(path.resolve(pluginText)).href;
|
||||
}
|
||||
plugin = await requireOrImport(pluginText);
|
||||
}
|
||||
catch (error) {
|
||||
throw new Error(`Cannot load plugin "${pluginText}": ${error.message}.`, { cause: error });
|
||||
}
|
||||
}
|
||||
}
|
||||
// some plugins do not use `module.exports` for their entry point,
|
||||
// in which case we try the named default export and the plugin name
|
||||
if (typeof plugin === 'object') {
|
||||
plugin = plugin.default || plugin[getCamelizedPluginBaseName(pluginText)];
|
||||
}
|
||||
if (!plugin) {
|
||||
throw new Error(`Cannot find entry for plugin "${pluginText}". The plugin needs to export a function either as "default" or "${getCamelizedPluginBaseName(pluginText)}" for Rollup to recognize it.`);
|
||||
}
|
||||
inputOptions.plugins.push(typeof plugin === 'function' ? plugin.call(plugin, pluginArgument) : plugin);
|
||||
}
|
||||
function getCamelizedPluginBaseName(pluginText) {
|
||||
return (pluginText.match(/(@rollup\/plugin-|rollup-plugin-)(.+)$/)?.[2] || pluginText)
|
||||
.split(/[/\\]/)
|
||||
.slice(-1)[0]
|
||||
.split('.')[0]
|
||||
.split('-')
|
||||
.map((part, index) => (index === 0 || !part ? part : part[0].toUpperCase() + part.slice(1)))
|
||||
.join('');
|
||||
}
|
||||
async function requireOrImport(pluginPath) {
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
return require(pluginPath);
|
||||
}
|
||||
catch {
|
||||
return import(pluginPath);
|
||||
}
|
||||
}
|
||||
|
||||
const loadConfigFile = async (fileName, commandOptions = {}, watchMode = false) => {
|
||||
const configs = await getConfigList(getDefaultFromCjs(await getConfigFileExport(fileName, commandOptions, watchMode)), commandOptions);
|
||||
const warnings = batchWarnings(commandOptions);
|
||||
try {
|
||||
const normalizedConfigs = [];
|
||||
for (const config of configs) {
|
||||
const options = await rollup.mergeOptions(config, watchMode, commandOptions, warnings.log);
|
||||
await addCommandPluginsToInputOptions(options, commandOptions);
|
||||
normalizedConfigs.push(options);
|
||||
}
|
||||
return { options: normalizedConfigs, warnings };
|
||||
}
|
||||
catch (error_) {
|
||||
warnings.flush();
|
||||
throw error_;
|
||||
}
|
||||
};
|
||||
async function getConfigFileExport(fileName, commandOptions, watchMode) {
|
||||
if (commandOptions.configPlugin || commandOptions.bundleConfigAsCjs) {
|
||||
try {
|
||||
return await loadTranspiledConfigFile(fileName, commandOptions);
|
||||
}
|
||||
catch (error_) {
|
||||
if (error_.message.includes('not defined in ES module scope')) {
|
||||
return parseAst_js.error(parseAst_js.logCannotBundleConfigAsEsm(error_));
|
||||
}
|
||||
throw error_;
|
||||
}
|
||||
}
|
||||
let cannotLoadEsm = false;
|
||||
const handleWarning = (warning) => {
|
||||
if (warning.message?.includes('To load an ES module') ||
|
||||
warning.message?.includes('Failed to load the ES module')) {
|
||||
cannotLoadEsm = true;
|
||||
}
|
||||
};
|
||||
process$1.on('warning', handleWarning);
|
||||
try {
|
||||
const fileUrl = node_url.pathToFileURL(fileName);
|
||||
if (watchMode) {
|
||||
// We are adding the current date to allow reloads in watch mode
|
||||
fileUrl.search = `?${Date.now()}`;
|
||||
}
|
||||
return (await import(fileUrl.href)).default;
|
||||
}
|
||||
catch (error_) {
|
||||
if (cannotLoadEsm) {
|
||||
return parseAst_js.error(parseAst_js.logCannotLoadConfigAsCjs(error_));
|
||||
}
|
||||
if (error_.message.includes('not defined in ES module scope')) {
|
||||
return parseAst_js.error(parseAst_js.logCannotLoadConfigAsEsm(error_));
|
||||
}
|
||||
throw error_;
|
||||
}
|
||||
finally {
|
||||
process$1.off('warning', handleWarning);
|
||||
}
|
||||
}
|
||||
function getDefaultFromCjs(namespace) {
|
||||
return namespace.default || namespace;
|
||||
}
|
||||
function getConfigImportAttributesKey(input) {
|
||||
if (input === 'assert' || input === 'with')
|
||||
return input;
|
||||
return;
|
||||
}
|
||||
async function loadTranspiledConfigFile(fileName, commandOptions) {
|
||||
const { bundleConfigAsCjs, configPlugin, configImportAttributesKey, silent } = commandOptions;
|
||||
const warnings = batchWarnings(commandOptions);
|
||||
const inputOptions = {
|
||||
// Do *not* specify external callback here - instead, perform the externality check it via fallback-plugin just below this comment.
|
||||
// This allows config plugin to first decide whether some import is external or not, and only then trigger the check in fallback-plugin.
|
||||
// Since the check is ultra-simple during this stage of transforming the config file itself, it should be fallback instead of primary check.
|
||||
// That way, e.g. importing workspace packages will work as expected - the workspace package will be bundled.
|
||||
input: fileName,
|
||||
onwarn: warnings.add,
|
||||
plugins: [],
|
||||
treeshake: false
|
||||
};
|
||||
await addPluginsFromCommandOption(configPlugin, inputOptions);
|
||||
// Add plugin as *last* item after addPluginsFromCommandOption is complete.
|
||||
// This plugin will trigger for imports not resolved by config plugin, and mark all non-relative imports as external.
|
||||
inputOptions.plugins.push({
|
||||
name: 'external-fallback',
|
||||
resolveId: source => {
|
||||
const looksLikeExternal = (source[0] !== '.' && !path.isAbsolute(source)) || source.slice(-5) === '.json';
|
||||
return looksLikeExternal ? false : null;
|
||||
}
|
||||
});
|
||||
const bundle = await rollup.rollup(inputOptions);
|
||||
const { output: [{ code }] } = await bundle.generate({
|
||||
exports: 'named',
|
||||
format: bundleConfigAsCjs ? 'cjs' : 'es',
|
||||
importAttributesKey: getConfigImportAttributesKey(configImportAttributesKey),
|
||||
plugins: [
|
||||
{
|
||||
name: 'transpile-import-meta',
|
||||
resolveImportMeta(property, { moduleId }) {
|
||||
if (property === 'url') {
|
||||
return `'${node_url.pathToFileURL(moduleId).href}'`;
|
||||
}
|
||||
if (property == 'filename') {
|
||||
return `'${moduleId}'`;
|
||||
}
|
||||
if (property == 'dirname') {
|
||||
return `'${path.dirname(moduleId)}'`;
|
||||
}
|
||||
if (property == null) {
|
||||
return `{url:'${node_url.pathToFileURL(moduleId).href}', filename: '${moduleId}', dirname: '${path.dirname(moduleId)}'}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
if (!silent && warnings.count > 0) {
|
||||
rollup.stderr(rollup.bold(`loaded ${parseAst_js.relativeId(fileName)} with warnings`));
|
||||
warnings.flush();
|
||||
}
|
||||
return loadConfigFromWrittenFile(path.join(path.dirname(fileName), `rollup.config-${Date.now()}.${bundleConfigAsCjs ? 'cjs' : 'mjs'}`), code);
|
||||
}
|
||||
async function loadConfigFromWrittenFile(bundledFileName, bundledCode) {
|
||||
await promises.writeFile(bundledFileName, bundledCode);
|
||||
try {
|
||||
return (await import(node_url.pathToFileURL(bundledFileName).href)).default;
|
||||
}
|
||||
finally {
|
||||
promises.unlink(bundledFileName).catch(error => console.warn(error?.message || error));
|
||||
}
|
||||
}
|
||||
async function getConfigList(configFileExport, commandOptions) {
|
||||
const config = await (typeof configFileExport === 'function'
|
||||
? configFileExport(commandOptions)
|
||||
: configFileExport);
|
||||
if (Object.keys(config).length === 0) {
|
||||
return parseAst_js.error(parseAst_js.logMissingConfig());
|
||||
}
|
||||
return Array.isArray(config) ? config : [config];
|
||||
}
|
||||
|
||||
exports.addCommandPluginsToInputOptions = addCommandPluginsToInputOptions;
|
||||
exports.batchWarnings = batchWarnings;
|
||||
exports.loadConfigFile = loadConfigFile;
|
||||
exports.stdinName = stdinName;
|
||||
//# sourceMappingURL=loadConfigFile.js.map
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
# `@tauri-apps/cli-win32-x64-msvc`
|
||||
|
||||
This is the **x86_64-pc-windows-msvc** binary for `@tauri-apps/cli`
|
||||
Reference in new issue
Block a user