Skip to content

Commit 2b3a9d6

Browse files
authored
createRequire and log error in Tailwind config (#745)
* Log the error from @theguild/components resolution * createRequire for new Tailwind patch * Update Tailwind config with createRequire and error logging Added createRequire function and error logging in Tailwind config.
1 parent f7b4d91 commit 2b3a9d6

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

.changeset/mean-nails-mix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@theguild/tailwind-config": patch
3+
---
4+
5+
createRequire and log error in Tailwind config

packages/tailwind-config/src/tailwind.config.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from 'node:path';
22
import { type Config } from 'tailwindcss';
33
import tailwindContainerQueries from '@tailwindcss/container-queries';
44
import { hiveColors } from './hive-colors.js';
5+
import { createRequire } from 'node:module';
56

67
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- tailwindcss types are incorrect
78
const makePrimaryColor: any =
@@ -15,25 +16,24 @@ const makePrimaryColor: any =
1516
};
1617

1718
function getComponentsPatterns() {
19+
const cwd = process.cwd();
20+
let require = globalThis.require;
1821
try {
19-
/**
20-
* We explicitly do not use `import { createRequire } from 'node:module'` and
21-
* `const require = createRequire(import.meta.url)` because it works even without it.
22-
* E.g. storybook complains about cannot found `module` package
23-
*/
24-
const componentsPackageJson = require.resolve('@theguild/components/package.json', {
22+
if (typeof require === "undefined") require = createRequire(cwd);
23+
24+
const componentsPackageJson = require.resolve("@theguild/components/package.json", {
2525
/**
2626
* Paths to resolve module location from CWD. Without specifying, it picks incorrect
2727
* `@theguild/components`, also must be relative
2828
*/
29-
paths: [process.cwd()],
29+
paths: [cwd]
3030
});
31-
3231
return [
33-
path.relative(process.cwd(), path.posix.join(componentsPackageJson, '..', 'dist/**/*.js')),
32+
path.relative(cwd, path.posix.join(componentsPackageJson, "..", "dist/**/*.js"))
3433
];
35-
} catch {
36-
console.warn("Can't find `@theguild/components` package.");
34+
} catch (err) {
35+
console.error("Failed to find `@theguild/components` package in ", cwd);
36+
console.error(err);
3737
return [];
3838
}
3939
}

0 commit comments

Comments
 (0)