Skip to content

ESM

Compare
Choose a tag to compare
@wkillerud wkillerud released this 18 Mar 14:06
· 33 commits to main since this release
0b54fd3

Breaking changes

  • The package is now an ES module.
  • Removed support for sending in a path or list of paths to parse. The parse function now behaves like the old parseString.

Migrating to use the ES module

This will depend on your setup. I'll link to a great overview by Sindre Sorhus:

Additionally, I found this discussion helpful:

I'm a user of this package myself, in a CommonJS project compiled with TypeScript. For reference, here is the commit for the upgrade:

Migrating from the old parse

The old parse function was a fairly trivial wrapper around parseString. Below, doParse does what the old parse function did. With this change, the package can more easily be used in the browser, should need be.

import fs from "node:fs/promises";
import { parse } from "scss-sassdoc-parser";

export async function doParse(path: string | string[]): Promise<ParseResult[]> {
  const paths = Array.isArray(path) ? path : [path];
  const result = await Promise.all(
    paths.map(async (src) => {
      const code = await fs.readFile(src, "utf-8");
      return await parse(code);
    }),
  );
  return result.flat();
}

const singlePathResult = await doParse("_helpers.scss");
const arrayOfPathsResult = await doParse(["_mixins.scss", "_functions.scss"]);

Migrating from the old parseString

Replace parseString with parse.

- import { parseString } from "scss-sassdoc-parser";
+ import { parse } from "scss-sassdoc-parser";

async function doParse() {
-  const result = await parseString(`
+  const result = await parse(`
/// Keeps it secret
/// @output Sets display to hidden
@mixin _keep-it-secret {
  display: hidden;
}
`);

doParse();

What's Changed

Full Changelog: v1.0.5...v2.0.0