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(sprites): correct imports for node12 #2749

Merged
merged 1 commit into from
Mar 20, 2023
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: 2 additions & 3 deletions packages/sprites/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable no-console */
import { command, multioption, flag, number, restPositionals, array, string } from 'cmd-ts';
import { writeFile } from 'fs/promises';
import path from 'path';
import { listSprites, ValidExtensions } from './fs.js';
import { Sprites } from './sprites.js';
Expand Down Expand Up @@ -83,8 +82,8 @@ export async function buildSprites(
outputPath = path.join(output, outputPath);
}

await writeFile(`${outputPath}.json`, JSON.stringify(res.layout, null, 2));
await writeFile(`${outputPath}.png`, res.buffer);
await fs.writeFile(`${outputPath}.json`, JSON.stringify(res.layout, null, 2));
await fs.writeFile(`${outputPath}.png`, res.buffer);
stats.push({
sheet: sheetName,
path: outputPath,
Expand Down
6 changes: 3 additions & 3 deletions packages/sprites/src/fs.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { readdir, readFile } from 'node:fs/promises';
import { promises as fs } from 'node:fs';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering what is the difference between import { promises as fs } from 'node:fs'; and import { promises as fs } from 'fs'; ?

import path, { join, parse } from 'node:path';
import { SvgId } from './sprites.js';

export const ValidExtensions = new Set(['.svg']);

export async function listSprites(spritePath: string, validExtensions = ValidExtensions): Promise<SvgId[]> {
const files = await readdir(spritePath);
const files = await fs.readdir(spritePath);
const sprites = files.filter((f) => validExtensions.has(path.extname(f.toLowerCase())));
if (sprites.length === 0) {
throw new Error('No files found: ' + spritePath + ' with extension: ' + [...ValidExtensions].join(','));
Expand All @@ -15,7 +15,7 @@ export async function listSprites(spritePath: string, validExtensions = ValidExt
sprites.map(async (c) => {
return {
id: parse(c).name, // remove the extension .svg
buffer: await readFile(join(spritePath, c)),
buffer: await fs.readFile(join(spritePath, c)),
};
}),
);
Expand Down