init
This commit is contained in:
commit
42ef2f9674
468 files changed
+645161
No files matched your search
+324
@@ -0,0 +1,324 @@
|
||||
/*
|
||||
@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';
|
||||
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
||||
|
||||
const rollup = require('./rollup.js');
|
||||
const path = require('node:path');
|
||||
const process = require('node:process');
|
||||
const index = require('./index.js');
|
||||
const node_os = require('node:os');
|
||||
require('./parseAst.js');
|
||||
require('../native.js');
|
||||
require('path');
|
||||
require('node:perf_hooks');
|
||||
require('node:fs/promises');
|
||||
require('fs');
|
||||
require('util');
|
||||
require('stream');
|
||||
require('os');
|
||||
require('./fsevents-importer.js');
|
||||
require('events');
|
||||
|
||||
class FileWatcher {
|
||||
constructor(task, chokidarOptions) {
|
||||
this.transformWatchers = new Map();
|
||||
this.chokidarOptions = chokidarOptions;
|
||||
this.task = task;
|
||||
this.watcher = this.createWatcher(null);
|
||||
}
|
||||
close() {
|
||||
this.watcher.close();
|
||||
for (const watcher of this.transformWatchers.values()) {
|
||||
watcher.close();
|
||||
}
|
||||
}
|
||||
unwatch(id) {
|
||||
this.watcher.unwatch(id);
|
||||
const transformWatcher = this.transformWatchers.get(id);
|
||||
if (transformWatcher) {
|
||||
this.transformWatchers.delete(id);
|
||||
transformWatcher.close();
|
||||
}
|
||||
}
|
||||
watch(id, isTransformDependency) {
|
||||
if (isTransformDependency) {
|
||||
const watcher = this.transformWatchers.get(id) ?? this.createWatcher(id);
|
||||
watcher.add(id);
|
||||
this.transformWatchers.set(id, watcher);
|
||||
}
|
||||
else {
|
||||
this.watcher.add(id);
|
||||
}
|
||||
}
|
||||
createWatcher(transformWatcherId) {
|
||||
const task = this.task;
|
||||
const isLinux = node_os.platform() === 'linux';
|
||||
const isFreeBSD = node_os.platform() === 'freebsd';
|
||||
const isTransformDependency = transformWatcherId !== null;
|
||||
const handleChange = (id, event) => {
|
||||
const changedId = transformWatcherId || id;
|
||||
if (isLinux || isFreeBSD) {
|
||||
// unwatching and watching fixes an issue with chokidar where on certain systems,
|
||||
// a file that was unlinked and immediately recreated would create a change event
|
||||
// but then no longer any further events
|
||||
watcher.unwatch(changedId);
|
||||
watcher.add(changedId);
|
||||
}
|
||||
task.invalidate(changedId, { event, isTransformDependency });
|
||||
};
|
||||
const watcher = index.chokidar
|
||||
.watch([], this.chokidarOptions)
|
||||
.on('add', id => handleChange(id, 'create'))
|
||||
.on('change', id => handleChange(id, 'update'))
|
||||
.on('unlink', id => handleChange(id, 'delete'));
|
||||
return watcher;
|
||||
}
|
||||
}
|
||||
|
||||
const eventsRewrites = {
|
||||
create: {
|
||||
create: 'buggy',
|
||||
delete: null, //delete file from map
|
||||
update: 'create'
|
||||
},
|
||||
delete: {
|
||||
create: 'update',
|
||||
delete: 'buggy',
|
||||
update: 'buggy'
|
||||
},
|
||||
update: {
|
||||
create: 'buggy',
|
||||
delete: 'delete',
|
||||
update: 'update'
|
||||
}
|
||||
};
|
||||
class Watcher {
|
||||
constructor(optionsList, emitter) {
|
||||
this.buildDelay = 0;
|
||||
this.buildTimeout = null;
|
||||
this.closed = false;
|
||||
this.invalidatedIds = new Map();
|
||||
this.rerun = false;
|
||||
this.running = true;
|
||||
this.emitter = emitter;
|
||||
emitter.close = this.close.bind(this);
|
||||
this.tasks = optionsList.map(options => new Task(this, options));
|
||||
for (const { watch } of optionsList) {
|
||||
if (watch && typeof watch.buildDelay === 'number') {
|
||||
this.buildDelay = Math.max(this.buildDelay, watch.buildDelay);
|
||||
}
|
||||
}
|
||||
process.nextTick(() => this.run());
|
||||
}
|
||||
async close() {
|
||||
if (this.closed)
|
||||
return;
|
||||
this.closed = true;
|
||||
if (this.buildTimeout)
|
||||
clearTimeout(this.buildTimeout);
|
||||
for (const task of this.tasks) {
|
||||
task.close();
|
||||
}
|
||||
await this.emitter.emit('close');
|
||||
this.emitter.removeAllListeners();
|
||||
}
|
||||
invalidate(file) {
|
||||
if (file) {
|
||||
const previousEvent = this.invalidatedIds.get(file.id);
|
||||
const event = previousEvent ? eventsRewrites[previousEvent][file.event] : file.event;
|
||||
if (event === 'buggy') {
|
||||
//TODO: throws or warn? Currently just ignore, uses new event
|
||||
this.invalidatedIds.set(file.id, file.event);
|
||||
}
|
||||
else if (event === null) {
|
||||
this.invalidatedIds.delete(file.id);
|
||||
}
|
||||
else {
|
||||
this.invalidatedIds.set(file.id, event);
|
||||
}
|
||||
}
|
||||
if (this.running) {
|
||||
this.rerun = true;
|
||||
return;
|
||||
}
|
||||
if (this.buildTimeout)
|
||||
clearTimeout(this.buildTimeout);
|
||||
this.buildTimeout = setTimeout(async () => {
|
||||
this.buildTimeout = null;
|
||||
try {
|
||||
await Promise.all([...this.invalidatedIds].map(([id, event]) => this.emitter.emit('change', id, { event })));
|
||||
this.invalidatedIds.clear();
|
||||
await this.emitter.emit('restart');
|
||||
this.emitter.removeListenersForCurrentRun();
|
||||
this.run();
|
||||
}
|
||||
catch (error) {
|
||||
this.invalidatedIds.clear();
|
||||
await this.emitter.emit('event', {
|
||||
code: 'ERROR',
|
||||
error,
|
||||
result: null
|
||||
});
|
||||
await this.emitter.emit('event', {
|
||||
code: 'END'
|
||||
});
|
||||
}
|
||||
}, this.buildDelay);
|
||||
}
|
||||
async run() {
|
||||
this.running = true;
|
||||
await this.emitter.emit('event', {
|
||||
code: 'START'
|
||||
});
|
||||
for (const task of this.tasks) {
|
||||
await task.run();
|
||||
}
|
||||
this.running = false;
|
||||
await this.emitter.emit('event', {
|
||||
code: 'END'
|
||||
});
|
||||
if (this.rerun) {
|
||||
this.rerun = false;
|
||||
this.invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
class Task {
|
||||
constructor(watcher, options) {
|
||||
this.cache = { modules: [] };
|
||||
this.watchFiles = [];
|
||||
this.closed = false;
|
||||
this.invalidated = true;
|
||||
this.watched = new Set();
|
||||
this.watcher = watcher;
|
||||
this.options = options;
|
||||
this.skipWrite = Boolean(options.watch && options.watch.skipWrite);
|
||||
this.outputs = this.options.output;
|
||||
this.outputFiles = this.outputs.map(output => {
|
||||
if (output.file || output.dir)
|
||||
return path.resolve(output.file || output.dir);
|
||||
return undefined;
|
||||
});
|
||||
this.watchOptions = this.options.watch || {};
|
||||
this.filter = rollup.createFilter(this.watchOptions.include, this.watchOptions.exclude);
|
||||
this.fileWatcher = new FileWatcher(this, {
|
||||
...this.watchOptions.chokidar,
|
||||
disableGlobbing: true,
|
||||
ignoreInitial: true
|
||||
});
|
||||
}
|
||||
close() {
|
||||
this.closed = true;
|
||||
this.fileWatcher.close();
|
||||
}
|
||||
invalidate(id, details) {
|
||||
this.invalidated = true;
|
||||
if (details.isTransformDependency) {
|
||||
for (const module of this.cache.modules) {
|
||||
if (!module.transformDependencies.includes(id))
|
||||
continue;
|
||||
// effective invalidation
|
||||
module.originalCode = null;
|
||||
}
|
||||
}
|
||||
this.watcher.invalidate({ event: details.event, id });
|
||||
this.watchOptions.onInvalidate?.(id);
|
||||
}
|
||||
async run() {
|
||||
if (!this.invalidated)
|
||||
return;
|
||||
this.invalidated = false;
|
||||
const options = {
|
||||
...this.options,
|
||||
cache: this.cache
|
||||
};
|
||||
const start = Date.now();
|
||||
await this.watcher.emitter.emit('event', {
|
||||
code: 'BUNDLE_START',
|
||||
input: this.options.input,
|
||||
output: this.outputFiles
|
||||
});
|
||||
let result = null;
|
||||
try {
|
||||
result = await rollup.rollupInternal(options, this.watcher.emitter);
|
||||
if (this.closed) {
|
||||
return;
|
||||
}
|
||||
this.updateWatchedFiles(result);
|
||||
if (!this.skipWrite) {
|
||||
await Promise.all(this.outputs.map(output => result.write(output)));
|
||||
if (this.closed) {
|
||||
return;
|
||||
}
|
||||
this.updateWatchedFiles(result);
|
||||
}
|
||||
await this.watcher.emitter.emit('event', {
|
||||
code: 'BUNDLE_END',
|
||||
duration: Date.now() - start,
|
||||
input: this.options.input,
|
||||
output: this.outputFiles,
|
||||
result
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
if (!this.closed) {
|
||||
if (Array.isArray(error.watchFiles)) {
|
||||
for (const id of error.watchFiles) {
|
||||
this.watchFile(id);
|
||||
}
|
||||
}
|
||||
if (error.id) {
|
||||
this.cache.modules = this.cache.modules.filter(module => module.id !== error.id);
|
||||
}
|
||||
}
|
||||
await this.watcher.emitter.emit('event', {
|
||||
code: 'ERROR',
|
||||
error,
|
||||
result
|
||||
});
|
||||
}
|
||||
}
|
||||
updateWatchedFiles(result) {
|
||||
const previouslyWatched = this.watched;
|
||||
this.watched = new Set();
|
||||
this.watchFiles = result.watchFiles;
|
||||
this.cache = result.cache;
|
||||
for (const id of this.watchFiles) {
|
||||
this.watchFile(id);
|
||||
}
|
||||
for (const module of this.cache.modules) {
|
||||
for (const dependencyId of module.transformDependencies) {
|
||||
this.watchFile(dependencyId, true);
|
||||
}
|
||||
}
|
||||
for (const id of previouslyWatched) {
|
||||
if (!this.watched.has(id)) {
|
||||
this.fileWatcher.unwatch(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
watchFile(id, isTransformDependency = false) {
|
||||
if (!this.filter(id))
|
||||
return;
|
||||
this.watched.add(id);
|
||||
if (this.outputFiles.includes(id)) {
|
||||
throw new Error('Cannot import the generated bundle');
|
||||
}
|
||||
// this is necessary to ensure that any 'renamed' files
|
||||
// continue to be watched following an error
|
||||
this.fileWatcher.watch(id, isTransformDependency);
|
||||
}
|
||||
}
|
||||
|
||||
exports.Task = Task;
|
||||
exports.Watcher = Watcher;
|
||||
//# sourceMappingURL=watch.js.map
|
||||
+270
@@ -0,0 +1,270 @@
|
||||
'use strict'
|
||||
|
||||
const SINGLE_QUOTE = "'".charCodeAt(0)
|
||||
const DOUBLE_QUOTE = '"'.charCodeAt(0)
|
||||
const BACKSLASH = '\\'.charCodeAt(0)
|
||||
const SLASH = '/'.charCodeAt(0)
|
||||
const NEWLINE = '\n'.charCodeAt(0)
|
||||
const SPACE = ' '.charCodeAt(0)
|
||||
const FEED = '\f'.charCodeAt(0)
|
||||
const TAB = '\t'.charCodeAt(0)
|
||||
const CR = '\r'.charCodeAt(0)
|
||||
const OPEN_SQUARE = '['.charCodeAt(0)
|
||||
const CLOSE_SQUARE = ']'.charCodeAt(0)
|
||||
const OPEN_PARENTHESES = '('.charCodeAt(0)
|
||||
const CLOSE_PARENTHESES = ')'.charCodeAt(0)
|
||||
const OPEN_CURLY = '{'.charCodeAt(0)
|
||||
const CLOSE_CURLY = '}'.charCodeAt(0)
|
||||
const SEMICOLON = ';'.charCodeAt(0)
|
||||
const ASTERISK = '*'.charCodeAt(0)
|
||||
const COLON = ':'.charCodeAt(0)
|
||||
const AT = '@'.charCodeAt(0)
|
||||
|
||||
const RE_AT_END = /[\t\n\f\r "#'()/;[\\\]{}]/g
|
||||
const RE_WORD_END = /[\t\n\f\r !"#'():;@[\\\]{}]|\/(?=\*)/g
|
||||
const RE_BAD_BRACKET = /.[\r\n"'(/\\]/
|
||||
const RE_HEX_ESCAPE = /[\da-f]/i
|
||||
|
||||
module.exports = function tokenizer(input, options = {}) {
|
||||
let css = input.css.valueOf()
|
||||
let ignore = options.ignoreErrors
|
||||
|
||||
let code, content, escape, next, quote
|
||||
let currentToken, escaped, escapePos, n, prev
|
||||
|
||||
let length = css.length
|
||||
let pos = 0
|
||||
let buffer = []
|
||||
let returned = []
|
||||
let lastBadParen = -1
|
||||
|
||||
function position() {
|
||||
return pos
|
||||
}
|
||||
|
||||
function unclosed(what) {
|
||||
throw input.error('Unclosed ' + what, pos)
|
||||
}
|
||||
|
||||
function endOfFile() {
|
||||
return returned.length === 0 && pos >= length
|
||||
}
|
||||
|
||||
function nextToken(opts) {
|
||||
if (returned.length) return returned.pop()
|
||||
if (pos >= length) return
|
||||
|
||||
let ignoreUnclosed = opts ? opts.ignoreUnclosed : false
|
||||
|
||||
code = css.charCodeAt(pos)
|
||||
|
||||
switch (code) {
|
||||
case NEWLINE:
|
||||
case SPACE:
|
||||
case TAB:
|
||||
case CR:
|
||||
case FEED: {
|
||||
next = pos
|
||||
do {
|
||||
next += 1
|
||||
code = css.charCodeAt(next)
|
||||
} while (
|
||||
code === SPACE ||
|
||||
code === NEWLINE ||
|
||||
code === TAB ||
|
||||
code === CR ||
|
||||
code === FEED
|
||||
)
|
||||
|
||||
currentToken = ['space', css.slice(pos, next)]
|
||||
pos = next - 1
|
||||
break
|
||||
}
|
||||
|
||||
case OPEN_SQUARE:
|
||||
case CLOSE_SQUARE:
|
||||
case OPEN_CURLY:
|
||||
case CLOSE_CURLY:
|
||||
case COLON:
|
||||
case SEMICOLON:
|
||||
case CLOSE_PARENTHESES: {
|
||||
let controlChar = String.fromCharCode(code)
|
||||
currentToken = [controlChar, controlChar, pos]
|
||||
break
|
||||
}
|
||||
|
||||
case OPEN_PARENTHESES: {
|
||||
prev = buffer.length ? buffer.pop()[1] : ''
|
||||
n = css.charCodeAt(pos + 1)
|
||||
if (
|
||||
prev === 'url' &&
|
||||
n !== SINGLE_QUOTE &&
|
||||
n !== DOUBLE_QUOTE &&
|
||||
n !== SPACE &&
|
||||
n !== NEWLINE &&
|
||||
n !== TAB &&
|
||||
n !== FEED &&
|
||||
n !== CR
|
||||
) {
|
||||
next = pos
|
||||
do {
|
||||
escaped = false
|
||||
next = css.indexOf(')', next + 1)
|
||||
if (next === -1) {
|
||||
if (ignore || ignoreUnclosed) {
|
||||
next = pos
|
||||
break
|
||||
} else {
|
||||
unclosed('bracket')
|
||||
}
|
||||
}
|
||||
escapePos = next
|
||||
while (css.charCodeAt(escapePos - 1) === BACKSLASH) {
|
||||
escapePos -= 1
|
||||
escaped = !escaped
|
||||
}
|
||||
} while (escaped)
|
||||
|
||||
currentToken = ['brackets', css.slice(pos, next + 1), pos, next]
|
||||
|
||||
pos = next
|
||||
} else if (pos <= lastBadParen) {
|
||||
currentToken = ['(', '(', pos]
|
||||
} else {
|
||||
next = css.indexOf(')', pos + 1)
|
||||
content = css.slice(pos, next + 1)
|
||||
|
||||
if (next === -1 || RE_BAD_BRACKET.test(content)) {
|
||||
lastBadParen = next === -1 ? length : next
|
||||
currentToken = ['(', '(', pos]
|
||||
} else {
|
||||
currentToken = ['brackets', content, pos, next]
|
||||
pos = next
|
||||
}
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
case SINGLE_QUOTE:
|
||||
case DOUBLE_QUOTE: {
|
||||
quote = code === SINGLE_QUOTE ? "'" : '"'
|
||||
next = pos
|
||||
do {
|
||||
escaped = false
|
||||
next = css.indexOf(quote, next + 1)
|
||||
if (next === -1) {
|
||||
if (ignore || ignoreUnclosed) {
|
||||
next = pos + 1
|
||||
break
|
||||
} else {
|
||||
unclosed('string')
|
||||
}
|
||||
}
|
||||
escapePos = next
|
||||
while (css.charCodeAt(escapePos - 1) === BACKSLASH) {
|
||||
escapePos -= 1
|
||||
escaped = !escaped
|
||||
}
|
||||
} while (escaped)
|
||||
|
||||
currentToken = ['string', css.slice(pos, next + 1), pos, next]
|
||||
pos = next
|
||||
break
|
||||
}
|
||||
|
||||
case AT: {
|
||||
RE_AT_END.lastIndex = pos + 1
|
||||
RE_AT_END.test(css)
|
||||
if (RE_AT_END.lastIndex === 0) {
|
||||
next = css.length - 1
|
||||
} else {
|
||||
next = RE_AT_END.lastIndex - 2
|
||||
}
|
||||
|
||||
currentToken = ['at-word', css.slice(pos, next + 1), pos, next]
|
||||
|
||||
pos = next
|
||||
break
|
||||
}
|
||||
|
||||
case BACKSLASH: {
|
||||
next = pos
|
||||
escape = true
|
||||
while (css.charCodeAt(next + 1) === BACKSLASH) {
|
||||
next += 1
|
||||
escape = !escape
|
||||
}
|
||||
code = css.charCodeAt(next + 1)
|
||||
if (
|
||||
escape &&
|
||||
code !== SLASH &&
|
||||
code !== SPACE &&
|
||||
code !== NEWLINE &&
|
||||
code !== TAB &&
|
||||
code !== CR &&
|
||||
code !== FEED
|
||||
) {
|
||||
next += 1
|
||||
if (RE_HEX_ESCAPE.test(css.charAt(next))) {
|
||||
while (RE_HEX_ESCAPE.test(css.charAt(next + 1))) {
|
||||
next += 1
|
||||
}
|
||||
if (css.charCodeAt(next + 1) === SPACE) {
|
||||
next += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentToken = ['word', css.slice(pos, next + 1), pos, next]
|
||||
|
||||
pos = next
|
||||
break
|
||||
}
|
||||
|
||||
default: {
|
||||
if (code === SLASH && css.charCodeAt(pos + 1) === ASTERISK) {
|
||||
next = css.indexOf('*/', pos + 2) + 1
|
||||
if (next === 0) {
|
||||
if (ignore || ignoreUnclosed) {
|
||||
next = css.length
|
||||
} else {
|
||||
unclosed('comment')
|
||||
}
|
||||
}
|
||||
|
||||
currentToken = ['comment', css.slice(pos, next + 1), pos, next]
|
||||
pos = next
|
||||
} else {
|
||||
RE_WORD_END.lastIndex = pos + 1
|
||||
RE_WORD_END.test(css)
|
||||
if (RE_WORD_END.lastIndex === 0) {
|
||||
next = css.length - 1
|
||||
} else {
|
||||
next = RE_WORD_END.lastIndex - 2
|
||||
}
|
||||
|
||||
currentToken = ['word', css.slice(pos, next + 1), pos, next]
|
||||
buffer.push(currentToken)
|
||||
pos = next
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
pos++
|
||||
return currentToken
|
||||
}
|
||||
|
||||
function back(token) {
|
||||
returned.push(token)
|
||||
}
|
||||
|
||||
return {
|
||||
back,
|
||||
endOfFile,
|
||||
nextToken,
|
||||
position
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user