Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolved filepath, async parser await #1083

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gold-countries-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'style-dictionary': patch
---

Fix parsers async support, use resolved filePath instead of raw.
21 changes: 10 additions & 11 deletions lib/utils/combineJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,32 +70,31 @@ export default async function combineJSON(

for (let i = 0; i < files.length; i++) {
const filePath = files[i];
const resolvedPath = resolve(filePath);
let file_content = null;
try {
// Iterate over custom parsers, if the file path matches the parser's
// pattern regex, use it's parse function to generate the object
parsers.forEach(({ pattern, parse }) => {
for (const { pattern, parse } of parsers) {
if (filePath.match(pattern)) {
file_content = parse({
contents: /** @type {string} */ (fs.readFileSync(resolve(filePath), 'utf-8')),
filePath,
file_content = await parse({
contents: /** @type {string} */ (fs.readFileSync(resolvedPath, 'utf-8')),
filePath: resolvedPath,
});
}
});
}

// If there is no file_content then no custom parser ran on that file
if (!file_content) {
if (['.js', '.mjs'].includes(extname(filePath))) {
let _filePath = resolve(filePath);
let resolvedPath = resolve(filePath);
// eslint-disable-next-line no-undef
if (typeof window !== 'object' && process?.platform === 'win32') {
// Windows FS compatibility. If in browser, we use an FS shim which doesn't require this Windows workaround
_filePath = new URL(`file:///${_filePath}`).href;
resolvedPath = new URL(`file:///${resolvedPath}`).href;
}
file_content = (await import(/* webpackIgnore: true */ _filePath)).default;
file_content = (await import(/* webpackIgnore: true */ resolvedPath)).default;
} else {
file_content = JSON5.parse(
/** @type {string} */ (fs.readFileSync(resolve(filePath), 'utf-8')),
/** @type {string} */ (fs.readFileSync(resolvedPath, 'utf-8')),
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading