Skip to content

Commit

Permalink
Merge pull request #554 from epaew/feature/esm
Browse files Browse the repository at this point in the history
Publish as native ESM
  • Loading branch information
epaew authored Nov 26, 2022
2 parents 58c411e + 5c6c8fc commit 2872358
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 75 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

## BREAKING CHANGES

- [#554](https://github.com/epaew/react-liff/pull/554)
- Publish as native ESM.

## Others

- [#492](https://github.com/epaew/react-liff/pull/492)
Expand Down
14 changes: 8 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
module.exports = {
// eslint-disable-next-line import/no-default-export
export default {
collectCoverageFrom: ['<rootDir>/src/**/*.ts{,x}', '!<rootDir>/src/**/*.test.ts{,x}'],
globals: {
'ts-jest': {
tsconfig: 'tsconfig.test.json',
},
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
preset: 'ts-jest',
preset: 'ts-jest/presets/default-esm',
testEnvironment: 'jsdom',
transform: {
'\\.tsx?$': ['ts-jest', { tsconfig: 'tsconfig.test.json', useESM: true }],
},
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"repository": "git@github.com:epaew/react-liff",
"license": "MIT",
"author": "Ryo Maeda <epaew.333@gmail.com>",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
Expand Down
4 changes: 2 additions & 2 deletions src/context/create-liff-context.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Liff } from '@line/liff';
import { createContext, useContext } from 'react';

import { createLiffProvider } from './create-liff-provider';
import { CreateLiffContext, LiffContextStates } from './types';
import { createLiffProvider } from './create-liff-provider.js';
import { CreateLiffContext, LiffContextStates } from './types.js';

export const createLiffContext: CreateLiffContext = () => {
const context = createContext<LiffContextStates>({
Expand Down
6 changes: 3 additions & 3 deletions src/context/create-liff-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Liff } from '@line/liff';
import * as PropTypes from 'prop-types';
import { createElement, FC, useEffect, useState } from 'react';

import { useLoginStateManager } from '../hooks';
import { getInitializedLiff } from '../lib';
import { useLoginStateManager } from '../hooks/index.js';
import { getInitializedLiff } from '../lib/index.js';

import { CreateLiffProvider, LiffProviderProps } from './types';
import { CreateLiffProvider, LiffProviderProps } from './types.js';

const LiffProviderPropTypes = {
children: PropTypes.element.isRequired,
Expand Down
2 changes: 1 addition & 1 deletion src/context/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { createLiffContext } from './create-liff-context';
import { createLiffContext } from './create-liff-context.js';

export const { LiffConsumer, LiffProvider, useLiff } = createLiffContext();
2 changes: 1 addition & 1 deletion src/context/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Liff } from '@line/liff';
import type { Consumer, Context, FC, ReactNode } from 'react';

import type { GetInitializedLiffProps } from '../lib';
import type { GetInitializedLiffProps } from '../lib/index.js';

export interface CreateLiffContext {
(): {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { useLoginStateManager } from './use-login-state-manager';
export { useLoginStateManager } from './use-login-state-manager.js';
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './context';
export * from './context/index.js';
6 changes: 5 additions & 1 deletion src/lib/get-initialized-liff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ interface GetInitializedLiffProps extends LiffConfig {

type GetInitializedLiff = (props: GetInitializedLiffProps) => Promise<Liff>;

const getLiff = async () => window.liff ?? (await import('@line/liff')).default;
const getLiff = async (): Promise<Liff> => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: This is an issue of @line/liff
return window.liff ?? ((await import('@line/liff')).default as Liff);
};

const registerLiffPlugin = (liff: Liff, plugin: Plugin) => {
Array.isArray(plugin) ? liff.use(...plugin) : liff.use(plugin);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './get-initialized-liff';
export * from './get-initialized-liff.js';
150 changes: 92 additions & 58 deletions tsconfig.json

Large diffs are not rendered by default.

0 comments on commit 2872358

Please sign in to comment.