From: Subject: Debian changes The Debian packaging of node-postcss-advanced-variables is maintained in git, using a workflow similar to the one described in dgit-maint-merge(7). The Debian delta is represented by this one combined patch; there isn't a patch queue that can be represented as a quilt series. A detailed breakdown of the changes is available from their canonical representation -- git commits in the packaging repository. For example, to see the changes made by the Debian maintainer in the first upload of upstream version 1.2.3, you could use: % git clone https://git.dgit.debian.org/node-postcss-advanced-variables % cd node-postcss-advanced-variables % git log --oneline 1.2.3..debian/1.2.3-1 -- . ':!debian' (If you have dgit, use `dgit clone node-postcss-advanced-variables`, rather than plain `git clone`.) We don't use debian/source/options single-debian-patch because it has bugs. Therefore, NMUs etc. may nevertheless have made additional patches. --- diff --git a/package.json b/package.json index 4893635..5635bfc 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,7 @@ "engines": { "node": ">=18" }, - "dependencies": { - "@csstools/sass-import-resolve": "^1.0.0" - }, + "dependencies": {}, "peerDependencies": { "postcss": "^8.4" }, diff --git a/src/index.js b/src/index.js index d32615b..bdb97d2 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,6 @@ // tooling import transformNode from './lib/transform-node'; -import resolve from '@csstools/sass-import-resolve'; +import resolve from './lib/resolve-import'; const matchProtocol = /^(?:[A-z]+:)?\/\//; diff --git a/src/lib/resolve-import.js b/src/lib/resolve-import.js new file mode 100644 index 0000000..0fd3ab0 --- /dev/null +++ b/src/lib/resolve-import.js @@ -0,0 +1,49 @@ +import fs from 'fs'; +import path from 'path'; + +export default function resolveImport(id, { cwd, readFile = false, cache = {} } = {}) { + const file = getImportCandidates(id, cwd || process.cwd()).find(isFile); + + if (!file) { + throw new Error(`Could not resolve ${id}`); + } + + const resolved = { file }; + + if (readFile) { + resolved.contents = cache[file] || fs.readFileSync(file, 'utf8'); + cache[file] = resolved.contents; + } + + return resolved; +} + +function getImportCandidates(id, cwd) { + const pathname = path.resolve(cwd, id); + const parsed = path.parse(pathname); + const names = parsed.ext ? [pathname] : [ + pathname, + `${pathname}.css`, + `${pathname}.scss` + ]; + + return names.flatMap(name => { + const dir = path.dirname(name); + const base = path.basename(name); + + return [ + name, + path.join(dir, `_${base}`), + path.join(name, 'index.css'), + path.join(name, 'index.scss') + ]; + }); +} + +function isFile(file) { + try { + return fs.statSync(file).isFile(); + } catch { + return false; + } +}