2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-06-20 20:00:33 +03:00

fix: proper module resolution in all cases (Node CJS, Node ESM, bundler)

* Add extensions to all imports

* Set module resolution to `bundler` to avoid Node specific behavior

* Use `ts2mjs` to rename files to `mjs`

* Add extensions to `@bbob/types` imports

* Fix `package.json` for proper ESM extension and type separation

* More module resolution stuff change (`node16` for everything, `node` for Vue 2 plugin)

* Use `ts-jest-resolver` for `js` -> `ts` resolving in Jest

* Add changeset

* Add import extensions to frontend libs
This commit is contained in:
Long Nguyen
2025-08-19 00:13:22 +07:00
committed by GitHub
parent 8126feb834
commit 0edd490a24
39 changed files with 287 additions and 124 deletions
+10 -5
View File
@@ -6,16 +6,21 @@
"bbob": "lib/cli.js"
},
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"module": "es/index.mjs",
"jsnext:main": "es/index.mjs",
"browser": "dist/index.js",
"browserName": "BbobCli",
"types": "types/index.d.ts",
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./es/index.js",
"require": "./lib/index.js",
"import": {
"types": "./types/index.d.mts",
"default": "./es/index.mjs"
},
"require": {
"types": "./types/index.d.ts",
"default": "./lib/index.js"
},
"browser": "./dist/index.min.js",
"umd": "./dist/index.min.js"
}
+1 -1
View File
@@ -1,4 +1,4 @@
#!/usr/bin/env node
import { run } from './index';
import { run } from './index.js';
run(process.stdin, process.stdout);
+10 -5
View File
@@ -25,16 +25,21 @@
"@bbob/types": "*"
},
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"module": "es/index.mjs",
"jsnext:main": "es/index.mjs",
"browser": "dist/index.js",
"browserName": "BbobCore",
"types": "types/index.d.ts",
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./es/index.js",
"require": "./lib/index.js",
"import": {
"types": "./types/index.d.mts",
"default": "./es/index.mjs"
},
"require": {
"types": "./types/index.d.ts",
"default": "./lib/index.js"
},
"browser": "./dist/index.min.js",
"umd": "./dist/index.min.js"
}
+2 -2
View File
@@ -9,8 +9,8 @@ import type {
} from "@bbob/types";
import { parse } from '@bbob/parser';
import { iterate, match } from './utils';
import { C1, C2 } from './errors'
import { iterate, match } from './utils.js';
import { C1, C2 } from './errors.js'
export function createTree<Options extends BBobCoreOptions = BBobCoreOptions>(tree: NodeContent[], options: Options) {
const extendedTree = tree as BBobCoreTagNodeTree
+10 -5
View File
@@ -14,16 +14,21 @@
"@bbob/types": "*"
},
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"module": "es/index.mjs",
"jsnext:main": "es/index.mjs",
"browser": "dist/index.js",
"browserName": "BbobHtml",
"types": "types/index.d.ts",
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./es/index.js",
"require": "./lib/index.js",
"import": {
"types": "./types/index.d.mts",
"default": "./es/index.mjs"
},
"require": {
"types": "./types/index.d.ts",
"default": "./lib/index.js"
},
"browser": "./dist/index.min.js",
"umd": "./dist/index.min.js"
}
+42 -17
View File
@@ -24,44 +24,69 @@
"@bbob/types": "*"
},
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"module": "es/index.mjs",
"jsnext:main": "es/index.mjs",
"browser": "dist/index.js",
"browserName": "BbobParser",
"types": "types/index.d.ts",
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./es/index.js",
"require": "./lib/index.js",
"import": {
"types": "./types/index.d.mts",
"default": "./es/index.mjs"
},
"require": {
"types": "./types/index.d.ts",
"default": "./lib/index.js"
},
"browser": "./dist/index.min.js",
"umd": "./dist/index.min.js"
},
"./lexer": {
"types": "./types/lexer.d.ts",
"import": "./es/lexer.js",
"require": "./lib/lexer.js",
"import": {
"types": "./types/lexer.d.mts",
"default": "./es/lexer.mjs"
},
"require": {
"types": "./types/lexer.d.ts",
"default": "./lib/lexer.js"
},
"browser": "./dist/index.min.js",
"umd": "./dist/index.min.js"
},
"./parse": {
"types": "./types/parse.d.ts",
"import": "./es/parse.js",
"require": "./lib/parse.js",
"import": {
"types": "./types/parse.d.mts",
"default": "./es/parse.mjs"
},
"require": {
"types": "./types/parse.d.ts",
"default": "./lib/parse.js"
},
"browser": "./dist/index.min.js",
"umd": "./dist/index.min.js"
},
"./Token": {
"types": "./types/Token.d.ts",
"import": "./es/Token.js",
"require": "./lib/Token.js",
"import": {
"types": "./types/Token.d.mts",
"default": "./es/Token.mjs"
},
"require": {
"types": "./types/Token.d.ts",
"default": "./lib/Token.js"
},
"browser": "./dist/index.min.js",
"umd": "./dist/index.min.js"
},
"./utils": {
"types": "./types/utils.d.ts",
"import": "./es/utils.js",
"require": "./lib/utils.js",
"import": {
"types": "./types/utils.d.mts",
"default": "./es/utils.mjs"
},
"require": {
"types": "./types/utils.d.ts",
"default": "./lib/utils.js"
},
"browser": "./dist/index.min.js",
"umd": "./dist/index.min.js"
}
+3 -3
View File
@@ -1,4 +1,4 @@
export { TagNode } from '@bbob/plugin-helper';
export { default } from './parse';
export * from './parse';
export * from './lexer'
export { default } from './parse.js';
export * from './parse.js';
export * from './lexer.js'
+2 -2
View File
@@ -14,8 +14,8 @@ import type { LexerOptions, LexerTokenizer } from "@bbob/types";
import {
Token, TYPE_ATTR_NAME, TYPE_ATTR_VALUE, TYPE_NEW_LINE, TYPE_SPACE, TYPE_TAG, TYPE_WORD,
} from './Token';
import { CharGrabber, createCharGrabber, trimChar, unquote } from './utils';
} from './Token.js';
import { CharGrabber, createCharGrabber, trimChar, unquote } from './utils.js';
// for cases <!-- -->
const EM = '!';
+2 -2
View File
@@ -7,9 +7,9 @@ import {
isTagNode,
} from "@bbob/plugin-helper";
import { createLexer } from "./lexer";
import { createLexer } from "./lexer.js";
import type { Token } from "./Token";
import type { Token } from "./Token.js";
class NodeList<Value> {
private n: Value[];
+34 -14
View File
@@ -15,8 +15,8 @@
"types"
],
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"module": "es/index.mjs",
"jsnext:main": "es/index.mjs",
"browser": "dist/index.js",
"browserName": "BbobPluginHelper",
"types": "types/index.d.ts",
@@ -25,30 +25,50 @@
},
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./es/index.js",
"require": "./lib/index.js",
"import": {
"types": "./types/index.d.mts",
"default": "./es/index.mjs"
},
"require": {
"types": "./types/index.d.ts",
"default": "./lib/index.js"
},
"browser": "./dist/index.min.js",
"umd": "./dist/index.min.js"
},
"./char": {
"types": "./types/char.d.ts",
"import": "./es/char.js",
"require": "./lib/char.js",
"import": {
"types": "./types/char.d.mts",
"default": "./es/char.mjs"
},
"require": {
"types": "./types/char.d.ts",
"default": "./lib/char.js"
},
"browser": "./dist/index.min.js",
"umd": "./dist/index.min.js"
},
"./helpers": {
"types": "./types/helpers.d.ts",
"import": "./es/helpers.js",
"require": "./lib/helpers.js",
"import": {
"types": "./types/helpers.d.mts",
"default": "./es/helpers.mjs"
},
"require": {
"types": "./types/helpers.d.ts",
"default": "./lib/helpers.js"
},
"browser": "./dist/index.min.js",
"umd": "./dist/index.min.js"
},
"./TagNode": {
"types": "./types/TagNode.d.ts",
"import": "./es/TagNode.js",
"require": "./lib/TagNode.js",
"import": {
"types": "./types/TagNode.d.mts",
"default": "./es/TagNode.mjs"
},
"require": {
"types": "./types/TagNode.d.ts",
"default": "./lib/TagNode.js"
},
"browser": "./dist/index.min.js",
"umd": "./dist/index.min.js"
}
+2 -2
View File
@@ -1,6 +1,6 @@
import type { NodeContent, TagNodeObject, TagNodeTree, TagPosition } from "@bbob/types";
import { OPEN_BRAKET, CLOSE_BRAKET, SLASH } from './char';
import { OPEN_BRAKET, CLOSE_BRAKET, SLASH } from './char.js';
import {
getUniqAttr,
getNodeLength,
@@ -8,7 +8,7 @@ import {
attrsToString,
attrValue,
isTagNode,
} from './helpers';
} from './helpers.js';
const getTagAttrs = <AttrValue>(tag: string, params: Record<string, AttrValue>) => {
const uniqAttr = getUniqAttr(params);
+2 -2
View File
@@ -1,7 +1,7 @@
import type { NodeContent, StringNode } from "@bbob/types";
import { N } from './char';
import type { TagNode } from "./TagNode";
import { N } from './char.js';
import type { TagNode } from "./TagNode.js";
function isTagNode(el: unknown): el is TagNode {
return typeof el === 'object' && el !== null && 'tag' in el;
+3 -3
View File
@@ -1,3 +1,3 @@
export * from "./helpers";
export * from "./char";
export * from "./TagNode";
export * from "./helpers.js";
export * from "./char.js";
export * from "./TagNode.js";
+10 -5
View File
@@ -17,16 +17,21 @@
"@bbob/html": "*"
},
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"module": "es/index.mjs",
"jsnext:main": "es/index.mjs",
"browser": "dist/index.js",
"browserName": "BbobPresetHTML5",
"types": "types/index.d.ts",
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./es/index.js",
"require": "./lib/index.js",
"import": {
"types": "./types/index.d.mts",
"default": "./es/index.mjs"
},
"require": {
"types": "./types/index.d.ts",
"default": "./lib/index.js"
},
"browser": "./dist/index.min.js",
"umd": "./dist/index.min.js"
}
+1 -1
View File
@@ -1,6 +1,6 @@
/* eslint-disable indent */
import { createPreset } from "@bbob/preset";
import defaultTags from "./defaultTags";
import defaultTags from "./defaultTags.js";
export type * from "@bbob/preset";
export default createPreset(defaultTags);
+10 -5
View File
@@ -20,16 +20,21 @@
"@types/react": "18.x"
},
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"module": "es/index.mjs",
"jsnext:main": "es/index.mjs",
"browser": "dist/index.js",
"browserName": "BbobPresetReact",
"types": "types/index.d.ts",
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./es/index.js",
"require": "./lib/index.js",
"import": {
"types": "./types/index.d.mts",
"default": "./es/index.mjs"
},
"require": {
"types": "./types/index.d.ts",
"default": "./lib/index.js"
},
"browser": "./dist/index.min.js",
"umd": "./dist/index.min.js"
}
+10 -5
View File
@@ -12,16 +12,21 @@
"@bbob/types": "*"
},
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"module": "es/index.mjs",
"jsnext:main": "es/index.mjs",
"browser": "dist/index.js",
"browserName": "BbobPresetVue",
"types": "types/index.d.ts",
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./es/index.js",
"require": "./lib/index.js",
"import": {
"types": "./types/index.d.mts",
"default": "./es/index.mjs"
},
"require": {
"types": "./types/index.d.ts",
"default": "./lib/index.js"
},
"browser": "./dist/index.min.js",
"umd": "./dist/index.min.js"
}
+10 -5
View File
@@ -22,16 +22,21 @@
"@bbob/core": "*"
},
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"module": "es/index.mjs",
"jsnext:main": "es/index.mjs",
"browser": "dist/index.js",
"browserName": "BbobPreset",
"types": "types/index.d.ts",
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./es/index.js",
"require": "./lib/index.js",
"import": {
"types": "./types/index.d.mts",
"default": "./es/index.mjs"
},
"require": {
"types": "./types/index.d.ts",
"default": "./lib/index.js"
},
"browser": "./dist/index.min.js",
"umd": "./dist/index.min.js"
}
+2 -2
View File
@@ -1,2 +1,2 @@
export { default } from "./preset";
export * from "./preset";
export { default } from "./preset.js";
export * from "./preset.js";
+10 -5
View File
@@ -26,16 +26,21 @@
"@types/react": "18.x"
},
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"module": "es/index.mjs",
"jsnext:main": "es/index.mjs",
"browser": "dist/index.js",
"browserName": "BbobReact",
"types": "types/index.d.ts",
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./es/index.js",
"require": "./lib/index.js",
"import": {
"types": "./types/index.d.mts",
"default": "./es/index.mjs"
},
"require": {
"types": "./types/index.d.ts",
"default": "./lib/index.js"
},
"browser": "./dist/index.min.js",
"umd": "./dist/index.min.js"
}
+1 -1
View File
@@ -1,7 +1,7 @@
import React, { ReactNode } from 'react';
import type { BBobPlugins, BBobCoreOptions } from '@bbob/types';
import { render } from './render';
import { render } from './render.js';
const content = (children: ReactNode, plugins?: BBobPlugins, options?: BBobCoreOptions) =>
React.Children.map(children,
+2 -2
View File
@@ -1,2 +1,2 @@
export { default } from './Component';
export { render } from './render';
export { default } from './Component.js';
export { render } from './render.js';
+11 -1
View File
@@ -14,7 +14,17 @@
"types"
],
"types": "types/index.d.ts",
"module": "types/index.d.ts",
"module": "types/index.d.mts",
"exports": {
".": {
"import": {
"types": "./types/index.d.mts"
},
"require": {
"types": "./types/index.d.ts"
}
}
},
"homepage": "https://github.com/JiLiZART/bbob",
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
"license": "MIT",
+2 -2
View File
@@ -1,5 +1,5 @@
import { ParseOptions } from "./parser";
import { NodeContent, PartialNodeContent, TagNodeObject, TagNodeTree } from "./common";
import { ParseOptions } from "./parser.js";
import { NodeContent, PartialNodeContent, TagNodeObject, TagNodeTree } from "./common.js";
export interface BBobCoreOptions<
Data = unknown | null,
+4 -4
View File
@@ -1,4 +1,4 @@
export * from './common'
export * from './parser'
export * from './core'
export * from './preset'
export * from './common.js'
export * from './parser.js'
export * from './core.js'
export * from './preset.js'
+1 -1
View File
@@ -1,4 +1,4 @@
import { TagNodeTree, TagPosition } from "./common";
import { TagNodeTree, TagPosition } from "./common.js";
export interface ParseError {
tagName: string;
+2 -2
View File
@@ -1,6 +1,6 @@
import { BBobCoreTagNodeTree, BBobPluginFunction, BBobPluginOptions } from "./core";
import { TagNodeObject } from "./common";
import { BBobCoreTagNodeTree, BBobPluginFunction, BBobPluginOptions } from "./core.js";
import { TagNodeObject } from "./common.js";
export type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>>
+10 -5
View File
@@ -25,16 +25,21 @@
"vue-template-compiler": "2.7.16"
},
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"module": "es/index.mjs",
"jsnext:main": "es/index.mjs",
"browser": "dist/index.js",
"browserName": "BbobVue",
"types": "types/index.d.ts",
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./es/index.js",
"require": "./lib/index.js",
"import": {
"types": "./types/index.d.mts",
"default": "./es/index.mjs"
},
"require": {
"types": "./types/index.d.ts",
"default": "./lib/index.js"
},
"browser": "./dist/index.min.js",
"umd": "./dist/index.min.js"
}
+1 -1
View File
@@ -1,7 +1,7 @@
import { defineComponent } from 'vue';
import type { BBobCoreOptions, BBobPlugins } from '@bbob/types';
import { render } from './render';
import { render } from './render.js';
export type BBobVueComponentProps = {
container: string
+2 -2
View File
@@ -1,5 +1,5 @@
import type { VueConstructor } from 'vue';
import Component from './Component';
import Component from './Component.js';
function install(vue: VueConstructor) {
vue.component("bbob-bbcode", Component);
@@ -7,6 +7,6 @@ function install(vue: VueConstructor) {
vue.component("BBCode", Component);
}
export { render } from './render';
export { render } from './render.js';
export { Component };
export default install;
+2 -1
View File
@@ -2,7 +2,8 @@
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "./types"
"outDir": "./types",
"moduleResolution": "node"
},
"include": [
"./src/**/*"
+10 -5
View File
@@ -29,16 +29,21 @@
"vue": "*"
},
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"module": "es/index.mjs",
"jsnext:main": "es/index.mjs",
"browser": "dist/index.js",
"browserName": "BbobVue3",
"types": "types/index.d.ts",
"exports": {
".": {
"types": "./types/index.d.ts",
"import": "./es/index.js",
"require": "./lib/index.js",
"import": {
"types": "./types/index.d.mts",
"default": "./es/index.mjs"
},
"require": {
"types": "./types/index.d.ts",
"default": "./lib/index.js"
},
"browser": "./dist/index.min.js",
"umd": "./dist/index.min.js"
}
+1 -1
View File
@@ -1,5 +1,5 @@
import { defineComponent, h, VNode } from "vue";
import { render } from "./render";
import { render } from "./render.js";
import type { BBobPlugins, BBobCoreOptions } from "@bbob/types";
+1 -1
View File
@@ -1,5 +1,5 @@
import type { Plugin } from "@vue/runtime-core";
import Component from "./Component";
import Component from "./Component.js";
const plugin = {
install(app) {