@parcel/transformer-stylus
Advanced tools
Comparing version 2.8.3 to 2.9.2
@@ -7,107 +7,74 @@ "use strict"; | ||
exports.default = void 0; | ||
function _plugin() { | ||
const data = require("@parcel/plugin"); | ||
_plugin = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _utils() { | ||
const data = require("@parcel/utils"); | ||
_utils = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _path() { | ||
const data = _interopRequireDefault(require("path")); | ||
_path = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _fs() { | ||
const data = _interopRequireDefault(require("fs")); | ||
_fs = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _stylus() { | ||
const data = _interopRequireDefault(require("stylus")); | ||
_stylus = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _parser() { | ||
const data = _interopRequireDefault(require("stylus/lib/parser")); | ||
_parser = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _depsResolver() { | ||
const data = _interopRequireDefault(require("stylus/lib/visitor/deps-resolver")); | ||
_depsResolver = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _nodes() { | ||
const data = _interopRequireDefault(require("stylus/lib/nodes")); | ||
_nodes = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _utils2() { | ||
const data = _interopRequireDefault(require("stylus/lib/utils")); | ||
_utils2 = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _evaluator() { | ||
const data = _interopRequireDefault(require("stylus/lib/visitor/evaluator")); | ||
_evaluator = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const URL_RE = /^(?:url\s*\(\s*)?['"]?(?:[#/]|(?:https?:)?\/\/)/i; | ||
var _default = new (_plugin().Transformer)({ | ||
@@ -117,22 +84,13 @@ async loadConfig({ | ||
}) { | ||
let configFile = await config.getConfig(['.stylusrc', '.stylusrc.js', '.stylusrc.cjs'], { | ||
let configFile = await config.getConfig(['.stylusrc', '.stylusrc.js', '.stylusrc.cjs', '.stylusrc.mjs'], { | ||
packageKey: 'stylus' | ||
}); | ||
if (configFile) { | ||
let isJavascript = _path().default.extname(configFile.filePath).endsWith('js'); | ||
if (isJavascript) { | ||
config.invalidateOnStartup(); | ||
} // Resolve relative paths from config file | ||
// Resolve relative paths from config file | ||
if (configFile.contents.paths) { | ||
configFile.contents.paths = configFile.contents.paths.map(p => _path().default.resolve(_path().default.dirname(configFile.filePath), p)); | ||
} | ||
return configFile.contents; | ||
} | ||
}, | ||
async transform({ | ||
@@ -146,7 +104,8 @@ asset, | ||
let code = await asset.getCode(); | ||
let style = (0, _stylus().default)(code, { ...stylusConfig | ||
let style = (0, _stylus().default)(code, { | ||
...stylusConfig | ||
}); | ||
style.set('filename', asset.filePath); | ||
style.set('include css', true); // Setup a handler for the URL function so we add dependencies for linked assets. | ||
style.set('include css', true); | ||
// Setup a handler for the URL function so we add dependencies for linked assets. | ||
style.define('url', node => { | ||
@@ -171,7 +130,4 @@ let filename = asset.addURLDependency(node.val, { | ||
} | ||
}); | ||
exports.default = _default; | ||
function attemptResolve(importedPath, filepath, asset, resolve, deps) { | ||
@@ -181,7 +137,5 @@ if (deps.has(importedPath)) { | ||
} | ||
if ((0, _utils().isGlob)(importedPath)) { | ||
// Invalidate when new files are created that match the glob pattern. | ||
let absoluteGlob = _path().default.resolve(_path().default.dirname(filepath), importedPath); | ||
asset.invalidateOnFileCreate({ | ||
@@ -192,8 +146,11 @@ glob: absoluteGlob | ||
onlyFiles: true | ||
}).then(entries => Promise.all(entries.map(entry => resolve(filepath, './' + _path().default.relative(_path().default.dirname(filepath), entry)))))); | ||
}).then(entries => Promise.all(entries.map(entry => resolve(filepath, './' + _path().default.relative(_path().default.dirname(filepath), entry), { | ||
packageConditions: ['stylus', 'style'] | ||
}))))); | ||
} else { | ||
deps.set(importedPath, resolve(filepath, importedPath)); | ||
deps.set(importedPath, resolve(filepath, importedPath, { | ||
packageConditions: ['stylus', 'style'] | ||
})); | ||
} | ||
} | ||
async function getDependencies(code, filepath, asset, resolve, options, parcelOptions, nativeGlob, seen = new Set(), includeImports = true) { | ||
@@ -205,3 +162,2 @@ seen.add(filepath); | ||
let deps = new Map(); | ||
if (includeImports && options.imports) { | ||
@@ -212,3 +168,2 @@ for (let importedPath of options.imports) { | ||
} | ||
class ImportVisitor extends _depsResolver().default { | ||
@@ -219,7 +174,6 @@ visitImport(imported) { | ||
} | ||
} | ||
new ImportVisitor(ast, options).visit(ast); | ||
new ImportVisitor(ast, options).visit(ast); // Recursively process depdendencies, and return a map with all resolved paths. | ||
// Recursively process depdendencies, and return a map with all resolved paths. | ||
let res = new Map(); | ||
@@ -232,5 +186,3 @@ await Promise.all(Array.from(deps.entries()).map(async ([importedPath, resolved]) => { | ||
} | ||
let found; | ||
if (resolved && (!Array.isArray(resolved) || resolved.length > 0)) { | ||
@@ -242,29 +194,26 @@ found = Array.isArray(resolved) ? resolved : [resolved]; | ||
// We just need to do this to keep track of the dependencies - stylus does the real work. | ||
// support optional .styl | ||
let originalPath = importedPath; | ||
if (!/\.styl$/i.test(importedPath)) { | ||
importedPath += '.styl'; | ||
} // Patch the native FS so we use Parcel's FS, and track files that are | ||
} | ||
// Patch the native FS so we use Parcel's FS, and track files that are | ||
// checked so we invalidate the cache when they are created. | ||
let restore = patchNativeFS(asset.fs, nativeGlob); | ||
let paths = [...new Set((options.paths || []).concat(_path().default.dirname(filepath || '.')))]; | ||
found = _utils2().default.find(importedPath, paths, filepath); | ||
if (!found) { | ||
found = _utils2().default.lookupIndex(originalPath, paths, filepath); | ||
} | ||
for (let invalidation of restore()) { | ||
asset.invalidateOnFileCreate(invalidation); | ||
} | ||
if (!found) { | ||
throw new Error('failed to locate file ' + originalPath); | ||
} | ||
} // Recursively process resolved files as well to get nested deps | ||
} | ||
// Recursively process resolved files as well to get nested deps | ||
for (let resolved of found) { | ||
@@ -274,3 +223,2 @@ if (!seen.has(resolved)) { | ||
let code = await asset.fs.readFile(resolved, 'utf8'); | ||
for (let [path, resolvedPath] of await getDependencies(code, resolved, asset, resolve, options, parcelOptions, nativeGlob, seen, false)) { | ||
@@ -284,8 +232,8 @@ res.set(path, resolvedPath); | ||
} | ||
async function createEvaluator(code, asset, resolve, options, parcelOptions, nativeGlob) { | ||
const deps = await getDependencies(code, asset.filePath, asset, resolve, options, parcelOptions, nativeGlob); | ||
async function createEvaluator(code, asset, resolve, options, parcelOptions, nativeGlob) { | ||
const deps = await getDependencies(code, asset.filePath, asset, resolve, options, parcelOptions, nativeGlob); // This is a custom stylus evaluator that extends stylus with support for the node | ||
// This is a custom stylus evaluator that extends stylus with support for the node | ||
// require resolution algorithm. It also adds all dependencies to the parcel asset | ||
// tree so the file watcher works correctly, etc. | ||
class CustomEvaluator extends _evaluator().default { | ||
@@ -295,8 +243,8 @@ visitImport(imported) { | ||
let path = node.string; | ||
if (node.name !== 'url' && path && !URL_RE.test(path)) { | ||
let resolved = deps.get(path); | ||
if (node.name !== 'url' && path && !URL_RE.test(path)) { | ||
let resolved = deps.get(path); // First try resolving using the node require resolution algorithm. | ||
// First try resolving using the node require resolution algorithm. | ||
// This allows stylus files in node_modules to be resolved properly. | ||
// If we find something, update the AST so stylus gets the absolute path to load later. | ||
if (resolved) { | ||
@@ -317,7 +265,8 @@ if (!Array.isArray(resolved)) { | ||
} | ||
} // Patch the native FS so stylus uses Parcel's FS to read the file. | ||
} | ||
// Patch the native FS so stylus uses Parcel's FS to read the file. | ||
let restore = patchNativeFS(asset.fs, nativeGlob); | ||
let restore = patchNativeFS(asset.fs, nativeGlob); // Done. Let stylus do its thing. | ||
// Done. Let stylus do its thing. | ||
let res = super.visitImport(imported); | ||
@@ -327,21 +276,16 @@ restore(); | ||
} | ||
} | ||
return CustomEvaluator; | ||
} | ||
function patchNativeFS(fs, nativeGlob) { | ||
let invalidations = []; | ||
let readFileSync = _fs().default.readFileSync; | ||
let statSync = _fs().default.statSync; | ||
let statSync = _fs().default.statSync; // $FlowFixMe | ||
// $FlowFixMe | ||
_fs().default.readFileSync = (filename, encoding) => { | ||
return fs.readFileSync(filename, encoding); | ||
}; // $FlowFixMe | ||
}; | ||
// $FlowFixMe | ||
_fs().default.statSync = p => { | ||
@@ -357,13 +301,10 @@ try { | ||
} | ||
throw err; | ||
} | ||
}; // Patch the `glob` module as well so we use the Parcel FS and track invalidations. | ||
}; | ||
// Patch the `glob` module as well so we use the Parcel FS and track invalidations. | ||
let glob = nativeGlob.sync; | ||
nativeGlob.sync = p => { | ||
let res = (0, _utils().globSync)(p, fs); | ||
if (!p.includes(`node_modules${_path().default.sep}stylus`)) { | ||
@@ -382,10 +323,8 @@ // Sometimes stylus passes file paths with no glob parts to the `glob` module. | ||
} | ||
return res; | ||
}; | ||
return () => { | ||
// $FlowFixMe | ||
_fs().default.readFileSync = readFileSync; // $FlowFixMe | ||
_fs().default.readFileSync = readFileSync; | ||
// $FlowFixMe | ||
_fs().default.statSync = statSync; | ||
@@ -396,10 +335,8 @@ nativeGlob.sync = glob; | ||
} | ||
/** | ||
* Puts the content of all given node blocks into the first one, essentially merging them. | ||
*/ | ||
function mergeBlocks(blocks) { | ||
let finalBlock; | ||
for (const block of blocks) { | ||
@@ -413,4 +350,3 @@ if (finalBlock) { | ||
} | ||
return finalBlock; | ||
} |
{ | ||
"name": "@parcel/transformer-stylus", | ||
"version": "2.8.3", | ||
"version": "2.9.2", | ||
"license": "MIT", | ||
@@ -20,10 +20,10 @@ "publishConfig": { | ||
"node": ">= 12.0.0", | ||
"parcel": "^2.8.3" | ||
"parcel": "^2.9.2" | ||
}, | ||
"dependencies": { | ||
"@parcel/plugin": "2.8.3", | ||
"@parcel/utils": "2.8.3", | ||
"@parcel/plugin": "2.9.2", | ||
"@parcel/utils": "2.9.2", | ||
"stylus": "^0.55.0" | ||
}, | ||
"gitHead": "349a6caf40ec8abb6a49fcae0765f8f8deb2073d" | ||
"gitHead": "76aa20fc2f752fae9c7347f071ea457b112a5dad" | ||
} |
@@ -19,3 +19,3 @@ // @flow | ||
let configFile = await config.getConfig( | ||
['.stylusrc', '.stylusrc.js', '.stylusrc.cjs'], | ||
['.stylusrc', '.stylusrc.js', '.stylusrc.cjs', '.stylusrc.mjs'], | ||
{ | ||
@@ -27,7 +27,2 @@ packageKey: 'stylus', | ||
if (configFile) { | ||
let isJavascript = path.extname(configFile.filePath).endsWith('js'); | ||
if (isJavascript) { | ||
config.invalidateOnStartup(); | ||
} | ||
// Resolve relative paths from config file | ||
@@ -106,2 +101,5 @@ if (configFile.contents.paths) { | ||
'./' + path.relative(path.dirname(filepath), entry), | ||
{ | ||
packageConditions: ['stylus', 'style'], | ||
}, | ||
), | ||
@@ -113,3 +111,8 @@ ), | ||
} else { | ||
deps.set(importedPath, resolve(filepath, importedPath)); | ||
deps.set( | ||
importedPath, | ||
resolve(filepath, importedPath, { | ||
packageConditions: ['stylus', 'style'], | ||
}), | ||
); | ||
} | ||
@@ -116,0 +119,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
629
22292
+ Added@lmdb/lmdb-darwin-arm64@2.7.11(transitive)
+ Added@lmdb/lmdb-darwin-x64@2.7.11(transitive)
+ Added@lmdb/lmdb-linux-arm@2.7.11(transitive)
+ Added@lmdb/lmdb-linux-arm64@2.7.11(transitive)
+ Added@lmdb/lmdb-linux-x64@2.7.11(transitive)
+ Added@lmdb/lmdb-win32-x64@2.7.11(transitive)
+ Added@parcel/cache@2.9.2(transitive)
+ Added@parcel/codeframe@2.9.2(transitive)
+ Added@parcel/diagnostic@2.9.2(transitive)
+ Added@parcel/events@2.9.2(transitive)
+ Added@parcel/fs@2.9.2(transitive)
+ Added@parcel/fs-search@2.9.2(transitive)
+ Added@parcel/hash@2.9.2(transitive)
+ Added@parcel/logger@2.9.2(transitive)
+ Added@parcel/markdown-ansi@2.9.2(transitive)
+ Added@parcel/node-resolver-core@3.0.2(transitive)
+ Added@parcel/package-manager@2.9.2(transitive)
+ Added@parcel/plugin@2.9.2(transitive)
+ Added@parcel/profiler@2.9.2(transitive)
+ Added@parcel/types@2.9.2(transitive)
+ Added@parcel/utils@2.9.2(transitive)
+ Added@parcel/workers@2.9.2(transitive)
+ Addedlmdb@2.7.11(transitive)
+ Addedmsgpackr@1.8.5(transitive)
+ Addednode-gyp-build-optional-packages@5.0.6(transitive)
- Removed@lmdb/lmdb-darwin-arm64@2.5.2(transitive)
- Removed@lmdb/lmdb-darwin-x64@2.5.2(transitive)
- Removed@lmdb/lmdb-linux-arm@2.5.2(transitive)
- Removed@lmdb/lmdb-linux-arm64@2.5.2(transitive)
- Removed@lmdb/lmdb-linux-x64@2.5.2(transitive)
- Removed@lmdb/lmdb-win32-x64@2.5.2(transitive)
- Removed@parcel/cache@2.8.3(transitive)
- Removed@parcel/codeframe@2.8.3(transitive)
- Removed@parcel/diagnostic@2.8.3(transitive)
- Removed@parcel/events@2.8.3(transitive)
- Removed@parcel/fs@2.8.3(transitive)
- Removed@parcel/fs-search@2.8.3(transitive)
- Removed@parcel/hash@2.8.3(transitive)
- Removed@parcel/logger@2.8.3(transitive)
- Removed@parcel/markdown-ansi@2.8.3(transitive)
- Removed@parcel/package-manager@2.8.3(transitive)
- Removed@parcel/plugin@2.8.3(transitive)
- Removed@parcel/types@2.8.3(transitive)
- Removed@parcel/utils@2.8.3(transitive)
- Removed@parcel/workers@2.8.3(transitive)
- Removedlmdb@2.5.2(transitive)
- Removednode-gyp-build-optional-packages@5.0.3(transitive)
Updated@parcel/plugin@2.9.2
Updated@parcel/utils@2.9.2