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 +1 -3
- package/dist/index.cjs +81 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +81 -45
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -18
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][![
|
|
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][](https://www.bestpractices.dev/projects/13115) [](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
|
-
|
|
652
|
-
|
|
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(
|
|
713
|
+
duplicateNameMap.get(duplicateKey)?.locations.add(location);
|
|
656
714
|
};
|
|
657
|
-
const collectFile = (file, sourceFile, node,
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
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,
|
|
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
|
|
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((
|
|
708
|
-
if (
|
|
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
|
-
|
|
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.
|
|
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.
|