Skip to content

Commit ea5d790

Browse files
authored
fix: mkdtemp for nested path (#13)
1 parent 9234f59 commit ea5d790

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/TailwindCSSRspackPlugin.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ class TailwindRspackPluginImpl {
195195
});
196196
}
197197

198+
async ensureTempDir(entryName: string): Promise<string> {
199+
const prefix = path.join(tmpdir(), entryName);
200+
await mkdir(path.dirname(prefix), { recursive: true });
201+
return await mkdtemp(prefix);
202+
}
203+
198204
async #prepareTailwindConfig(
199205
entryName: string,
200206
entryModules: Set<string>,
@@ -211,7 +217,7 @@ class TailwindRspackPluginImpl {
211217
'.rsbuild',
212218
entryName,
213219
)
214-
: await mkdtemp(path.join(tmpdir(), entryName));
220+
: await this.ensureTempDir(entryName);
215221

216222
if (DEBUG) {
217223
await mkdir(outputDir, { recursive: true });

test/basic/index.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,37 @@ test('should not generate tailwind.config.js in dist/', async () => {
7878

7979
expect(existsSync(resolve(__dirname, './dist/.rsbuild'))).toBeFalsy();
8080
});
81+
82+
test('should dev with nested entry', async ({ page }) => {
83+
const rsbuild = await createRsbuild({
84+
cwd: __dirname,
85+
rsbuildConfig: {
86+
source: {
87+
entry: {
88+
'nested/output/folder/bundle': resolve(__dirname, './src/index.js'),
89+
},
90+
},
91+
plugins: [pluginTailwindCSS()],
92+
server: {
93+
port: getRandomPort(),
94+
},
95+
},
96+
});
97+
98+
const { server, urls } = await rsbuild.startDevServer();
99+
100+
await page.goto(`${urls[0]}/nested/output/folder/bundle`);
101+
102+
const display = await page.evaluate(() => {
103+
const el = document.getElementById('test');
104+
if (!el) {
105+
throw new Error('#test not found');
106+
}
107+
108+
return window.getComputedStyle(el).getPropertyValue('display');
109+
});
110+
111+
expect(display).toBe('flex');
112+
113+
await server.close();
114+
});

0 commit comments

Comments
 (0)