From 21cd1eabff753487b61eff6ab0a1ee6d74bc524c Mon Sep 17 00:00:00 2001 From: McLaynV <25386191+McLaynV@users.noreply.github.com> Date: Mon, 16 Jan 2023 11:42:02 +0100 Subject: [PATCH 1/2] docs: fix JSON in README (#430) * Add missing comma in the example `bulma-css-vars.config.js` * Reorder R-G-B in the standard order --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 086f63b..087d60e 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ import { hsl, rgb } from 'bulma-css-vars' const appColors = { black: hsl(0, 0, 4), 'scheme-main': rgb(200, 105, 84), - red: { r: 255, b: 0, g: 0} + red: { r: 255, g: 0, b: 0 }, primary: '#663423', blue: 'blue', } From 6a669dc6932ad330a41c3810a243aab71acfcaff Mon Sep 17 00:00:00 2001 From: Sacha Stafyniak Date: Tue, 17 Jan 2023 07:07:17 +0100 Subject: [PATCH 2/2] fix(cli): allow to load cjs file, and force cjs for cli for node 18+ (#426) --- .../{bulma-css-vars.js => bulma-css-vars.cjs} | 2 +- lib/package.json | 2 +- lib/src/cli.ts | 26 ++++++++++++++++--- lib/tsconfig-esm.json | 2 +- lib/tsconfig.json | 3 ++- 5 files changed, 28 insertions(+), 7 deletions(-) rename lib/bin/{bulma-css-vars.js => bulma-css-vars.cjs} (74%) diff --git a/lib/bin/bulma-css-vars.js b/lib/bin/bulma-css-vars.cjs similarity index 74% rename from lib/bin/bulma-css-vars.js rename to lib/bin/bulma-css-vars.cjs index 0a31b45..97a53ad 100755 --- a/lib/bin/bulma-css-vars.js +++ b/lib/bin/bulma-css-vars.cjs @@ -1,5 +1,5 @@ #!/usr/bin/env node -const { runCli, runCliInit } = require('../dist/cli.js') +const { runCli, runCliInit } = require('../dist/cjs/cli.js') const cwd = process.cwd() diff --git a/lib/package.json b/lib/package.json index 4277fd5..4e5e86a 100644 --- a/lib/package.json +++ b/lib/package.json @@ -27,7 +27,7 @@ "/*.sass" ], "bin": { - "bulma-css-vars": "bin/bulma-css-vars.js" + "bulma-css-vars": "bin/bulma-css-vars.cjs" }, "scripts": { "build": "tsc -p tsconfig.json && tsc -p tsconfig-esm.json && webpack", diff --git a/lib/src/cli.ts b/lib/src/cli.ts index 33ad95e..6fd4e21 100644 --- a/lib/src/cli.ts +++ b/lib/src/cli.ts @@ -1,4 +1,5 @@ import * as path from 'path' +import { existsSync } from 'fs' import { defaultOptions } from './default-options' import { BulmaCssVarsOptions, ColorCallSet } from './types' import { getUsedVariables } from './find-used-vars' @@ -14,22 +15,41 @@ import { getCssFallbacks } from './css-post-processor' import { compileSass } from './compile-sass' const configFileName = 'bulma-css-vars.config.js' +const cjsConfigFileName = 'bulma-css-vars.config.cjs' const mainSassFileName = 'src/main.scss' const configFilePathAtCwd = (cwd: string) => path.join(cwd, configFileName) +const cjsConfigFilePathAtCwd = (cwd: string) => path.join(cwd, cjsConfigFileName) const mainSassFilePathAtCwd = (cwd: string) => path.join(cwd, mainSassFileName) async function validateOptions(cwd: string) { const configFilePath = configFilePathAtCwd(cwd) + const cjsConfigFilePath = cjsConfigFilePathAtCwd(cwd) let loadedOptions = {} - try { - loadedOptions = require(configFilePath) - } catch (err) { + + if (existsSync(cjsConfigFilePath)) { + try { + loadedOptions = await import(cjsConfigFilePath).then(m => m.default || m) + } catch (err) { + throw new Error( + `Unable to parse configuration file at '${cjsConfigFilePath}': ${err}` + ) + } + } else if (existsSync(configFilePath)) { + try { + loadedOptions = await import(configFilePath).then(m => m.default || m) + } catch (err) { + throw new Error( + `Unable to parse cjs configuration file at '${configFilePath}': ${err}` + ) + } + } else { throw new Error( `Required config file '${configFileName}' was not found at ${configFilePath}` ) } + const options: BulmaCssVarsOptions = { ...defaultOptions, ...loadedOptions, diff --git a/lib/tsconfig-esm.json b/lib/tsconfig-esm.json index bc41dbc..f99918a 100644 --- a/lib/tsconfig-esm.json +++ b/lib/tsconfig-esm.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "module": "es2015", + "module": "es2020", "outDir": "./dist/esm" } } diff --git a/lib/tsconfig.json b/lib/tsconfig.json index 5cacb85..0ac3e44 100644 --- a/lib/tsconfig.json +++ b/lib/tsconfig.json @@ -9,7 +9,8 @@ "target": "es2015", "noImplicitAny": true, "lib": ["es2019", "dom"], - "downlevelIteration": true + "downlevelIteration": true, + "skipLibCheck": true }, "include": ["./src/**/*"], "exclude": ["node_modules", "dist", "**/__mocks__/**/*", "./src/**/*.test.ts"]