susee 1.6.0 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  [![NPM][nodei_img]][nodei_url]
10
10
 
11
- [![npm version][npm_v_img]][npm_v_url] [![license][license_img]](LICENSE) [![mmcov][mmcov_svg]][mmcov_url] [![publish to npm][publish_npm_svg]][publish_npm][![CodeQL Advanced][code_ql_svg]][code_ql] [![OpenSSF Baseline](https://www.bestpractices.dev/projects/13115/baseline)](https://www.bestpractices.dev/projects/13115) [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/13115/badge)](https://www.bestpractices.dev/projects/13115)
11
+ [![npm version][npm_v_img]][npm_v_url] [![license][license_img]](LICENSE) [![mmcov][mmcov_svg]][mmcov_url] [![publish to npm][publish_npm_svg]][publish_npm][![OpenSSF Baseline](https://www.bestpractices.dev/projects/13115/baseline)](https://www.bestpractices.dev/projects/13115) [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/13115/badge)](https://www.bestpractices.dev/projects/13115)
12
12
 
13
13
  ## About
14
14
 
@@ -366,7 +366,5 @@ Violations print an error and exit with code `1`.
366
366
  [license_img]: https://img.shields.io/npm/l/susee
367
367
  [publish_npm]: https://github.com/phothinmg/susee/actions/workflows/npm-publish.yml
368
368
  [publish_npm_svg]: https://github.com/phothinmg/susee/actions/workflows/npm-publish.yml/badge.svg?event=release
369
- [code_ql]: https://github.com/phothinmg/susee/actions/workflows/codeql.yml
370
- [code_ql_svg]: https://github.com/phothinmg/susee/actions/workflows/codeql.yml/badge.svg
371
369
  [mmcov_svg]: https://img.shields.io/badge/mmcov-85.01%25-green?style=flat&labelColor=%232c3e50
372
370
  [mmcov_url]: https://suseejs.org/coverage
package/dist/index.cjs CHANGED
@@ -639,78 +639,114 @@ var utils;
639
639
  gen.findProperty = findProperty;
640
640
  })(gen = utils.gen || (utils.gen = {})); // namespace gen
641
641
  })(utils || (utils = {})); // namespace utils
642
+ const getScopeNodeLabel = (sourceFile, node, index) => {
643
+ if (ts6_1.default.isModuleDeclaration(node)) {
644
+ return `namespace:${node.name.getText(sourceFile)}`;
645
+ }
646
+ if (ts6_1.default.isClassDeclaration(node)) {
647
+ return `class:${node.name?.text ?? `anonymous-${index}`}`;
648
+ }
649
+ if (ts6_1.default.isFunctionDeclaration(node) || ts6_1.default.isFunctionExpression(node)) {
650
+ return `function:${node.name?.text ?? `anonymous-${index}`}`;
651
+ }
652
+ if (ts6_1.default.isArrowFunction(node)) {
653
+ return `arrow:${index}`;
654
+ }
655
+ if (ts6_1.default.isMethodDeclaration(node)) {
656
+ return `method:${node.name.getText(sourceFile)}`;
657
+ }
658
+ if (ts6_1.default.isBlock(node)) {
659
+ return `block:${index}`;
660
+ }
661
+ return `${ts6_1.default.SyntaxKind[node.kind].toLowerCase()}:${index}`;
662
+ };
663
+ const getScopeKey = (file, scopeStack) => {
664
+ if (scopeStack.length === 0) {
665
+ return "global";
666
+ }
667
+ return `${file}::${scopeStack.join(" > ")}`;
668
+ };
669
+ const isScopeNode = (node) => ts6_1.default.isModuleDeclaration(node) ||
670
+ ts6_1.default.isClassDeclaration(node) ||
671
+ ts6_1.default.isFunctionDeclaration(node) ||
672
+ ts6_1.default.isFunctionExpression(node) ||
673
+ ts6_1.default.isArrowFunction(node) ||
674
+ ts6_1.default.isMethodDeclaration(node) ||
675
+ ts6_1.default.isBlock(node);
676
+ const collectDeclarationNames = (node) => {
677
+ if (ts6_1.default.isVariableStatement(node)) {
678
+ return node.declarationList.declarations.flatMap((decl) => {
679
+ if (!ts6_1.default.isIdentifier(decl.name)) {
680
+ return [];
681
+ }
682
+ return [{ name: decl.name.text, positionNode: decl.name }];
683
+ });
684
+ }
685
+ if (ts6_1.default.isFunctionDeclaration(node) ||
686
+ ts6_1.default.isClassDeclaration(node) ||
687
+ ts6_1.default.isEnumDeclaration(node) ||
688
+ ts6_1.default.isInterfaceDeclaration(node) ||
689
+ ts6_1.default.isTypeAliasDeclaration(node)) {
690
+ if (node.name) {
691
+ return [{ name: node.name.text, positionNode: node.name }];
692
+ }
693
+ }
694
+ return [];
695
+ };
642
696
  const collectDuplicateDeclarations = (deps, bundledSourceFile) => {
643
697
  const duplicateNameMap = new Map();
644
- const addDuplicateDeclaration = (name, file, sourceFile, positionNode) => {
698
+ const addDuplicateDeclaration = (scopeKey, name, file, sourceFile, positionNode) => {
645
699
  const { line, character } = sourceFile.getLineAndCharacterOfPosition(positionNode.getStart(sourceFile));
646
700
  const location = {
647
701
  file,
648
702
  line: line + 1,
649
703
  column: character + 1,
650
704
  };
651
- if (!duplicateNameMap.has(name)) {
652
- duplicateNameMap.set(name, new Set([location]));
705
+ const duplicateKey = `${scopeKey}::${name}`;
706
+ if (!duplicateNameMap.has(duplicateKey)) {
707
+ duplicateNameMap.set(duplicateKey, {
708
+ name,
709
+ locations: new Set([location]),
710
+ });
653
711
  return;
654
712
  }
655
- duplicateNameMap.get(name)?.add(location);
713
+ duplicateNameMap.get(duplicateKey)?.locations.add(location);
656
714
  };
657
- const collectFile = (file, sourceFile, node, isGlobalScope = true) => {
658
- if (isGlobalScope) {
659
- if (ts6_1.default.isVariableStatement(node)) {
660
- node.declarationList.declarations.forEach((decl) => {
661
- if (ts6_1.default.isIdentifier(decl.name)) {
662
- const name = decl.name.text;
663
- addDuplicateDeclaration(name, file, sourceFile, decl.name);
664
- }
665
- });
666
- }
667
- else if (ts6_1.default.isFunctionDeclaration(node) ||
668
- ts6_1.default.isClassDeclaration(node) ||
669
- ts6_1.default.isEnumDeclaration(node) ||
670
- ts6_1.default.isInterfaceDeclaration(node) ||
671
- ts6_1.default.isTypeAliasDeclaration(node)) {
672
- const name = node.name?.text;
673
- if (name) {
674
- addDuplicateDeclaration(name, file, sourceFile, node.name);
675
- }
676
- }
677
- }
678
- if (ts6_1.default.isBlock(node) ||
679
- ts6_1.default.isFunctionDeclaration(node) ||
680
- ts6_1.default.isFunctionExpression(node) ||
681
- ts6_1.default.isArrowFunction(node) ||
682
- ts6_1.default.isMethodDeclaration(node) ||
683
- ts6_1.default.isClassDeclaration(node)) {
684
- if (ts6_1.default.isBlock(node)) {
685
- node.statements.forEach((child) => collectFile(file, sourceFile, child, false));
686
- }
687
- else {
688
- ts6_1.default.forEachChild(node, (child) => {
689
- collectFile(file, sourceFile, child, false);
690
- });
691
- }
715
+ const collectFile = (file, sourceFile, node, scopeStack = []) => {
716
+ const scopeKey = getScopeKey(file, scopeStack);
717
+ for (const declaration of collectDeclarationNames(node)) {
718
+ addDuplicateDeclaration(scopeKey, declaration.name, file, sourceFile, declaration.positionNode);
719
+ }
720
+ if (isScopeNode(node)) {
721
+ const nextScopeStack = [
722
+ ...scopeStack,
723
+ getScopeNodeLabel(sourceFile, node, node.getStart(sourceFile)),
724
+ ];
725
+ ts6_1.default.forEachChild(node, (child) => {
726
+ collectFile(file, sourceFile, child, nextScopeStack);
727
+ });
692
728
  return;
693
729
  }
694
730
  ts6_1.default.forEachChild(node, (child) => {
695
- collectFile(file, sourceFile, child, isGlobalScope);
731
+ collectFile(file, sourceFile, child, scopeStack);
696
732
  });
697
733
  };
698
734
  for (const dep of deps) {
699
735
  const sourceFile = bundledSourceFile(dep.file, dep.content);
700
- collectFile(dep.file, sourceFile, sourceFile, true);
736
+ collectFile(dep.file, sourceFile, sourceFile);
701
737
  }
702
738
  return duplicateNameMap;
703
739
  };
704
740
  const checkDuplicates = (tree, bundledSourceFile) => {
705
741
  let _err = false;
706
742
  const duplicateNameMap = collectDuplicateDeclarations(tree.depFiles, bundledSourceFile);
707
- duplicateNameMap.forEach((files, name) => {
708
- if (files.size > 1) {
743
+ duplicateNameMap.forEach(({ name, locations }) => {
744
+ if (locations.size > 1) {
709
745
  _err = true;
710
746
  console.warn(color_1.default.yellow("[susee:error]"));
711
747
  console.warn(" Duplicate declarations found in your dependencies tree as follows:");
712
748
  console.warn(` - "${color_1.default.magenta(name)}" declared in multiple files : `);
713
- files.forEach((f) => console.warn(` - ${f.file}:${f.line}:${f.column}`));
749
+ locations.forEach((f) => console.warn(` - ${f.file}:${f.line}:${f.column}`));
714
750
  console.info("Please rename these with different names to avoid duplicate declarations.");
715
751
  }
716
752
  });
@@ -2422,7 +2458,7 @@ async function bundle(entry) {
2422
2458
  return await bundler(entry);
2423
2459
  }
2424
2460
  //package.json
2425
- const __jsonModule__package = { "name": "susee", "version": "1.6.0", "description": "TypeScript-first bundler for library packages", "type": "module", "main": "dist/index.cjs", "types": "dist/index.d.cts", "module": "dist/index.mjs", "exports": { ".": { "import": { "types": "./dist/index.d.mts", "default": "./dist/index.mjs" }, "require": { "types": "./dist/index.d.cts", "default": "./dist/index.cjs" } } }, "bin": { "susee": "bin/susee" }, "scripts": { "build": "tsx build.ts", "lint": "biome lint ./src ./__tests__ --write", "fmt": "biome format --write", "test": "tsx --test", "coverage": "npx tsx --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=__tests__/coverage/lcov.info", "hooks:install": "bash scripts/install-hooks.sh", "commit": "bash scripts/commit.sh", "v:patch": "npm version patch --no-git-tag-version", "v:minor": "npm version minor --no-git-tag-version", "v:major": "npm version major --no-git-tag-version", "vercel:install": "npm i mmcov shiki tsx && bundle install", "vercel:build": "bash scripts/vercel_build.sh", "docs:dev": "bundle exec jekyll serve --profile", "docs:init": "bash scripts/setup.sh" }, "keywords": ["bundler", "susee", "suseejs"], "author": { "name": "Pho Thin Mg", "email": "phothinmg@disroot.org", "url": "https://phothinmg.github.io/" }, "license": "Apache-2.0", "files": ["package.json", "README.md", "LICENSE", "dist/**/*", "bin/**/*"], "publishConfig": { "provenance": true, "access": "public" }, "repository": { "url": "git+https://github.com/phothinmg/susee.git", "type": "git" }, "homepage": "https://susee.js.org/", "bugs": { "url": "https://github.com/phothinmg/susee/issues" }, "dependencies": { "@suseejs/color": "^0.0.9", "@suseejs/ts6": "^1.0.0", "mmcov": "^0.0.8", "shiki": "^4.3.1" }, "devDependencies": { "@biomejs/biome": "^2.4.12", "@suseejs/banner-text-plugin": "^0.0.9", "@suseejs/terser-plugin": "^0.0.9", "@suseejs/type": "^0.0.9", "@types/node": "^25.6.0", "tsx": "^4.21.0", "typescript": "^7.0.2" }, "allowScripts": { "esbuild@0.28.1": true } };
2461
+ const __jsonModule__package = { "name": "susee", "version": "1.6.2", "description": "TypeScript-first bundler for library packages", "type": "module", "main": "dist/index.cjs", "types": "dist/index.d.cts", "module": "dist/index.mjs", "exports": { ".": { "import": { "types": "./dist/index.d.mts", "default": "./dist/index.mjs" }, "require": { "types": "./dist/index.d.cts", "default": "./dist/index.cjs" } } }, "bin": { "susee": "bin/susee" }, "scripts": { "build": "tsx build.ts", "lint": "biome lint ./src ./__tests__ --write", "fmt": "biome format --write", "test": "tsx --test", "hooks:install": "bash scripts/install-hooks.sh", "commit": "bash scripts/commit.sh", "v:patch": "npm version patch --no-git-tag-version", "v:minor": "npm version minor --no-git-tag-version", "v:major": "npm version major --no-git-tag-version" }, "keywords": ["bundler", "susee", "suseejs"], "author": "Pho Thin Mg <phothinmg@disroot.org> (https://phothinmg.github.io/)", "license": "Apache-2.0", "files": ["package.json", "README.md", "LICENSE", "dist/**/*", "bin/**/*"], "publishConfig": { "provenance": true, "access": "public" }, "repository": { "url": "git+https://github.com/phothinmg/susee.git", "type": "git" }, "homepage": "https://susee.js.org/", "bugs": { "url": "https://github.com/phothinmg/susee/issues" }, "dependencies": { "@suseejs/color": "^0.0.9", "@suseejs/ts6": "^1.0.0" }, "devDependencies": { "@biomejs/biome": "^2.4.12", "@suseejs/banner-text-plugin": "^0.0.9", "@suseejs/type": "^0.0.9", "@types/node": "^25.6.0", "tsx": "^4.23.1", "typescript": "^7.0.2" }, "allowScripts": { "esbuild@0.28.1": true }, "workspaces": ["susee-docs"] };
2426
2462
  /**
2427
2463
  * Finds the path of the susee.config file if it exists.
2428
2464
  * It checks for the existence of "susee.config.ts", "susee.config.js", and "susee.config.mjs" in the current working directory.