Skip to content

Commit

Permalink
chore: move browser->fs check to entrypoints conditional export
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenbroekema committed Oct 9, 2023
1 parent f723302 commit c6e3357
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
7 changes: 7 additions & 0 deletions index-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import node_fs from 'node:fs';
import StyleDictionary, { setFs as _setFs } from './index.js';

_setFs(node_fs);

export { fs } from './index.js';
export default StyleDictionary;
5 changes: 1 addition & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ import cleanAllPlatforms from './lib/cleanAllPlatforms.js';
// const SASS_MAP_FORMAT_DEPRECATION_WARNINGS = GroupMessages.GROUP.SassMapFormatDeprecationWarnings;

// Allow to be overridden by setter, set default to memfs for browser env, node:fs for node env
export let fs =
typeof window === 'object'
? (await import('@bundled-es-modules/memfs')).default
: (await import(/** webpackIgnore: true */ 'node:fs')).default;
export let fs = (await import('@bundled-es-modules/memfs')).default;

// since ES modules exports are read-only, use a setter
export const setFs = (_fs) => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"exports": {
".": {
"types": "./types/index.d.ts",
"node": "./index-node.js",
"default": "./index.js"
},
"./create-dictionary": "./lib/utils/createDictionary.js"
Expand Down

0 comments on commit c6e3357

Please sign in to comment.