Skip to content

Commit c3a665a

Browse files
authored
Support only ESM at first (line#794)
Eventually, we will support both ESM and CJS, but this change will first support ESM only. The changes are simple. 1. This changed `import hoge from "./hoge";` to `import hoge from "./hoge.js";` This is the majority of the changes. 2. This specified in the package.json that it is ESM (`"type": "module"`). 3. This modified the tsconfig.json for ESM. Subsequent changes will reintroduce support for CJS. As a result, line-bot-sdk-nodejs is expected to become a dual package.
1 parent 67122af commit c3a665a

File tree

229 files changed

+1100
-1060
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

229 files changed

+1100
-1060
lines changed

docs/.vitepress/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const utils = require('./utils.ts');
1+
import { copyFile, rewriteFile } from './utils.js';
22

3-
utils.copyFile('README.md', 'index.md');
4-
utils.copyFile('CONTRIBUTING.md', 'CONTRIBUTING.md');
3+
copyFile('README.md', 'index.md');
4+
copyFile('CONTRIBUTING.md', 'CONTRIBUTING.md');
55

6-
utils.rewriteFile('../apidocs/README.md', /\(CONTRIBUTING.md\)/g, '(../CONTRIBUTING.md)');
6+
rewriteFile('../apidocs/README.md', /\(CONTRIBUTING.md\)/g, '(../CONTRIBUTING.md)');
77

88
export default {
99
title: 'line-bot-sdk-nodejs',

docs/.vitepress/utils.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
1-
const fs = require('fs');
2-
const path = require('path');
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import {fileURLToPath} from 'node:url';
4+
import {dirname} from 'node:path';
5+
6+
// __dirname is not available in ESM, so we need to derive it
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = dirname(__filename);
39

410
function copyFile(sourceFilename, targetFilename) {
5-
const sourcePath = path.join(__dirname, '../../', sourceFilename);
6-
const targetPath = path.join(__dirname, '../', targetFilename);
7-
const md = fs.readFileSync(sourcePath, 'utf-8');
8-
fs.writeFileSync(targetPath, md);
11+
const sourcePath = path.join(__dirname, '../../', sourceFilename);
12+
const targetPath = path.join(__dirname, '../', targetFilename);
13+
const md = fs.readFileSync(sourcePath, 'utf-8');
14+
fs.writeFileSync(targetPath, md);
915
}
1016

1117
function rewriteFile(filename, regex, replacement) {
12-
console.log("Rewriting file: ", filename, " with regex: ", regex, " and replacement: ", replacement)
13-
const content = fs.readFileSync(path.join(__dirname, filename), 'utf-8');
14-
const newContent = content.replace(regex, replacement);
15-
fs.writeFileSync(path.join(__dirname, filename), newContent);
18+
console.log("Rewriting file: ", filename, " with regex: ", regex, " and replacement: ", replacement)
19+
const content = fs.readFileSync(path.join(__dirname, filename), 'utf-8');
20+
const newContent = content.replace(regex, replacement);
21+
fs.writeFileSync(path.join(__dirname, filename), newContent);
1622
}
1723

1824
export {
19-
copyFile,
20-
rewriteFile,
25+
copyFile,
26+
rewriteFile
2127
};

generate-code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def generate_webhook():
7676
run_command(f'rm -rf lib/webhook/tests/')
7777

7878
with open('lib/webhook/api.ts', 'w') as wfp:
79-
wfp.write("""export * from './model/models';""")
79+
wfp.write("""export * from './model/models.js';""")
8080

8181

8282
def main():
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{# @pebvariable name="apiInfo" type="org.openapitools.codegen.model.ApiInfoMap" #}
22
{% for api in apiInfo.apis -%}
3-
export { {{ api.operations.classname }} } from './{{ api.get("classFilename") }}';
3+
export { {{ api.operations.classname }} } from './{{ api.get("classFilename") }}.js';
44
{% endfor %}

generator/src/main/resources/line-bot-sdk-nodejs-generator/api-single.pebble

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
/* tslint:disable:no-unused-locals */
77
{% for import in imports -%}
8-
import { {{import.classname}} } from '{{import.filename}}';
8+
import { {{import.classname}} } from '{{import.filename}}.js';
99
{% endfor %}
10-
import * as Types from "../../types";
11-
import {ensureJSON} from "../../utils";
10+
import * as Types from "../../types.js";
11+
import {ensureJSON} from "../../utils.js";
1212
import {Readable} from "node:stream";
1313

14-
import HTTPFetchClient, { convertResponseToReadable } from "../../http-fetch";
14+
import HTTPFetchClient, { convertResponseToReadable } from "../../http-fetch.js";
1515

1616
// ===============================================
1717
// This file is autogenerated - Please do not edit
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This is the entrypoint for the package
2-
export * from './api/apis';
3-
export * from './model/models';
2+
export * from './api/apis.js';
3+
export * from './model/models.js';

generator/src/main/resources/line-bot-sdk-nodejs-generator/api_test.pebble

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{# @pebvariable name="imports" type="java.util.List<java.util.Map<String, String>>" #}
22
{# @pebvariable name="operations" type="org.openapitools.codegen.model.OperationMap" #}
33
{# @pebvariable name="authMethods" type="java.util.ArrayList<org.openapitools.codegen.CodegenSecurity>" -#}
4-
import { {{operations.classname}} } from "../../api";
4+
import { {{operations.classname}} } from "../../api.js";
55

66
{% for import in imports -%}
7-
import { {{import.classname}} } from '../{{import.filename}}';
7+
import { {{import.classname}} } from '../{{import.filename}}.js';
88
{% endfor %}
99

1010
import { createServer } from "node:http";

generator/src/main/resources/line-bot-sdk-nodejs-generator/model.pebble

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
{% for model in models %}
44

55
{% for tsi in model.get('tsImports') -%}
6-
import { {{ tsi.classname }} } from '{{ tsi.filename }}';
6+
import { {{ tsi.classname }} } from '{{ tsi.filename }}.js';
77
{%- endfor %}
88

99
{% if model.model.discriminator != null %}
1010
{% for model in model.model.discriminator.mappedModels -%}
11-
import { {{model.modelName}} } from './models';
11+
import { {{model.modelName}} } from './models.js';
1212
{% endfor %}
1313

1414
export type {{classname}} =
@@ -30,7 +30,7 @@ export type Unknown{{classname}} = {{classname}}Base & {
3030
{%- endif -%}
3131
{% if not model.model.isEnum -%}
3232
{% if model.model.parent != null %}
33-
import { {{ model.model.parent }}Base } from './models';
33+
import { {{ model.model.parent }}Base } from './models.js';
3434

3535
{% endif %}
3636
export type {{classname}}{% if model.model.discriminator != null %}Base{% endif %} = {% if model.model.parent != null %}{{ model.model.parent }}Base & {% endif %} { {% if model.model.vendorExtensions.get("x-selector") != null %}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{# @pebvariable name="models" type="java.util.ArrayList<org.openapitools.codegen.model.ModelMap>" #}
22
{% for model in models -%}
3-
export * from '{{ model.model.classFilename }}';
3+
export * from '{{ model.model.classFilename }}.js';
44
{%- endfor %}

lib/channel-access-token/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This is the entrypoint for the package
2-
export * from "./api/apis";
3-
export * from "./model/models";
2+
export * from "./api/apis.js";
3+
export * from "./model/models.js";

0 commit comments

Comments
 (0)