Skip to content

Commit

Permalink
fix: handle no local installed stylable (#1039)
Browse files Browse the repository at this point in the history
  • Loading branch information
idoros committed Jun 5, 2024
1 parent 9bedce9 commit a5a3d22
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,19 @@ async function loadConfigFile(configBasePath: string | null, suffixes: string[])
}

function fixConfigForOldVersions(config: Partial<StylableConfig>, rootFsPath: string) {
const corePackagePath = require.resolve('@stylable/core/package.json', { paths: [rootFsPath] });
const corePackageJson = fs.readJsonFileSync(corePackagePath) as { version: string };

if (corePackageJson?.version && semver.lt(corePackageJson.version, '6.0.0')) {
console.log(
`\nDetected old Stylable version: ${corePackageJson.version} < 6.0.0\n`,
config.experimentalSelectorInference
);
config.experimentalSelectorInference ??= false;
try {
const corePackagePath = require.resolve('@stylable/core/package.json', { paths: [rootFsPath] });
const corePackageJson = fs.readJsonFileSync(corePackagePath) as { version: string };

if (corePackageJson?.version && semver.lt(corePackageJson.version, '6.0.0')) {
console.log(
`\nDetected old Stylable version: ${corePackageJson.version} < 6.0.0\n`,
config.experimentalSelectorInference
);
config.experimentalSelectorInference ??= false;
}
} catch (e) {
const message = e instanceof Error ? e.message : String(e);
console.log(`\nFailed to detect project Stylable version: \n${message}\n`);
}
}

0 comments on commit a5a3d22

Please sign in to comment.