From 982842d138b53917dccab60410cced6d13a9ca82 Mon Sep 17 00:00:00 2001 From: Roy Revelt Date: Thu, 10 Aug 2023 07:06:52 +0100 Subject: [PATCH 1/4] feat: port the PR#8 onto latest main --- index.js | 9 ++++++++- test/index.test.js | 24 ++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 9f34edf..ab3e769 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +let path = require("path"); const { readFileSync } = require("fs"); const resolve = require("resolve"); @@ -21,9 +22,15 @@ module.exports = () => { .replace(/['"]?\s*(\))?$/, ""); let replacement; + + let basedir = process.cwd(); + if (node.source && node.source.input && node.source.input.file) { + basedir = path.dirname(node.source.input.file); + } + try { let resolvedPath = resolve.sync(id, { - basedir: process.cwd(), + basedir, extensions: [".css"], moduleDirectory: ["web_modules", "node_modules"], packageFilter: (pkg) => { diff --git a/test/index.test.js b/test/index.test.js index e5546c5..4cac5bf 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,3 +1,4 @@ +let path = require("path"); let { test } = require("uvu"); let { equal, match } = require("uvu/assert"); let postcss = require("postcss"); @@ -6,9 +7,9 @@ let nestedImport = require("../"); // ----------------------------------------------------------------------------- -async function run(input, output, opts) { +async function run(input, output, opts, from) { let result = await postcss([nestedImport(opts)]).process(input, { - from: undefined + from }); equal(result.css, output); equal(result.warnings().length, 0); @@ -189,4 +190,23 @@ test("09 - url() function with line breaks", async () => { ); }); +test("10 - import based on current directory", async () => { + await run( + `@media (prefers-color-scheme: light) { + :root:not([data-theme='dark']) { + @nested-import './mocks/colors1.css'; + } +}`, + `@media (prefers-color-scheme: light) { + :root:not([data-theme='dark']) { + h1 { + color: red; +} + } +}`, + undefined, + path.join(__dirname, "app.css") + ); +}); + test.run(); From 61f6e3ccecf2ee8141e731ed3d6a462da816da05 Mon Sep 17 00:00:00 2001 From: Roy Revelt Date: Mon, 28 Aug 2023 00:21:40 +0100 Subject: [PATCH 2/4] docs: prepare the changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9220b1e..9671c71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## 1.2.0 (2023-08-28) + +### Features + +- import files based on the current directory - thanks [linhe0x0](https://github.com/linhe0x0) + ## 1.1.0 (2023-08-10) ### Features From 481624997e83c8b2bb3432ef7969c18a3cf3584c Mon Sep 17 00:00:00 2001 From: Roy Revelt Date: Mon, 28 Aug 2023 00:23:59 +0100 Subject: [PATCH 3/4] fix: fix const vs let --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index ab3e769..ce597e1 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -let path = require("path"); +const path = require("path"); const { readFileSync } = require("fs"); const resolve = require("resolve"); From 611e6253941ae0cb521e5312e556ce8c89b4212a Mon Sep 17 00:00:00 2001 From: Roy Revelt Date: Mon, 28 Aug 2023 00:25:50 +0100 Subject: [PATCH 4/4] docs: mention Kristoffers test PR too --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9671c71..47f94f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline ### Features - import files based on the current directory - thanks [linhe0x0](https://github.com/linhe0x0) +- more unit tests — thanks [Kristoffer Nordström](https://github.com/42tte) ## 1.1.0 (2023-08-10)