Skip to content

Commit 8623026

Browse files
kemsakuraikemsakurai
andauthored
バージョンを1.6.2に更新し、exportsを追加 (#13)
* feat: バージョンを1.6.2に更新し、exportsを追加 * Migrate to ES modules and update import paths Converted the project to use ES module syntax by updating import/export statements and file extensions throughout the codebase. Changed the package type to 'module', updated tsconfig to use ESNext modules, and added tsconfig.node.json for Node.js ESM compatibility. Adjusted scripts and dependencies for ESM, and added cross-env for environment variable management. Also added a Mocha config for TypeScript ESM testing and improved Japanese tokenization with a new method. --------- Co-authored-by: kemsakurai <sakurai.kem@mail.com>
1 parent 442821e commit 8623026

29 files changed

+158
-78
lines changed

.mocharc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"loader": "ts-node/esm",
3+
"spec": "test/**/*.ts",
4+
"timeout": 10000,
5+
"recursive": true,
6+
"extensions": ["ts"],
7+
"require": ["ts-node/register"]
8+
}

eslint.config.js renamed to eslint.config.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const js = require('@eslint/js');
2-
const tseslint = require('@typescript-eslint/eslint-plugin');
3-
const tsparser = require('@typescript-eslint/parser');
1+
import js from '@eslint/js';
2+
import tseslint from '@typescript-eslint/eslint-plugin';
3+
import tsparser from '@typescript-eslint/parser';
44

5-
module.exports = [
5+
export default [
66
js.configs.recommended,
77
{
88
files: ['**/*.js'],

example/example.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import ContentBasedRecommender from '../src/lib/ContentBasedRecommender';
2-
import { Document } from '../src/types';
3-
import posts from '../fixtures/sample-documents';
4-
import tags from '../fixtures/sample-document-tags';
1+
import ContentBasedRecommender from '../src/lib/ContentBasedRecommender.js';
2+
import { Document } from '../src/types/index.js';
3+
import posts from '../fixtures/sample-documents.js';
4+
import tags from '../fixtures/sample-document-tags.js';
55

66
/**
77
* Content-Based Recommenderの使用例

fixtures/sample-document-tags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Document } from '../src/types';
1+
import { Document } from '../src/types/index.js';
22

33
/**
44
* サンプル文書タグデータ

fixtures/sample-documents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Document } from '../src/types';
1+
import { Document } from '../src/types/index.js';
22

33
/**
44
* サンプル文書データ

fixtures/sample-japanese-documents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Document } from '../src/types';
1+
import { Document } from '../src/types/index.js';
22

33
/**
44
* サンプル日本語文書データ

fixtures/sample-target-documents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Document } from '../src/types';
1+
import { Document } from '../src/types/index.js';
22

33
/**
44
* サンプルターゲット文書データ

index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
* Content-Based Recommender メインエントリーポイント
33
* コンテンツベース推薦システムのメインクラスをエクスポート
44
*/
5-
export { default } from './src/lib/ContentBasedRecommender';
6-
export * from './src/types';
5+
export { default } from './src/lib/ContentBasedRecommender.js';
6+
export * from './src/types/index.js';

package-lock.json

Lines changed: 22 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
11
{
22
"name": "ts-content-based-recommender",
3-
"version": "1.6.1",
3+
"version": "1.6.2",
44
"description": "A TypeScript-based content-based recommender with multilingual support (Japanese & English). Forked from content-based-recommender.",
5+
"type": "module",
56
"homepage": "https://github.com/kensakurai/ts-content-based-recommender",
67
"repository": {
78
"type": "git",
89
"url": "git://github.com/kensakurai/ts-content-based-recommender.git"
910
},
1011
"main": "dist/index.js",
12+
"module": "dist/index.js",
1113
"types": "dist/index.d.ts",
14+
"exports": {
15+
".": {
16+
"types": "./dist/index.d.ts",
17+
"import": "./dist/index.js",
18+
"require": "./dist/index.js",
19+
"default": "./dist/index.js"
20+
}
21+
},
1222
"scripts": {
1323
"build": "tsc",
1424
"prepublishOnly": "npm run build",
1525
"lint": "npx tsc --noEmit && eslint 'src/**/*.ts' 'test/**/*.ts'",
1626
"lint:fix": "eslint 'src/**/*.ts' 'test/**/*.ts' --fix",
1727
"tsc": "tsc --noEmit",
18-
"test": "./node_modules/.bin/mocha --require ts-node/register 'test/**/*.ts'",
19-
"example": "npx ts-node example/example.ts",
20-
"dev": "npx ts-node"
28+
"test": "npm run build && mocha dist/test/**/*.js",
29+
"test:ts": "cross-env NODE_OPTIONS='--loader=ts-node/esm' mocha test/**/*.ts",
30+
"example": "node --loader ts-node/esm example/example.ts",
31+
"dev": "node --loader ts-node/esm"
2132
},
2233
"keywords": [
2334
"content-based",
@@ -77,13 +88,20 @@
7788
"@typescript-eslint/eslint-plugin": "^8.35.0",
7889
"@typescript-eslint/parser": "^8.35.0",
7990
"chai": "^4.5.0",
91+
"cross-env": "^7.0.3",
8092
"eslint": "^8.57.1",
8193
"eslint-config-airbnb-base": "^15.0.0",
8294
"eslint-plugin-import": "^2.32.0",
8395
"mocha": "^11.7.1",
8496
"ts-node": "^10.9.2",
8597
"typescript": "^5.8.3"
8698
},
99+
"ts-node": {
100+
"esm": true,
101+
"experimentalSpecifierResolution": "node",
102+
"transpileOnly": true,
103+
"files": true
104+
},
87105
"peerDependencies": {
88106
"typescript": ">=4.5.0"
89107
}

0 commit comments

Comments
 (0)