Skip to content

Commit

Permalink
enhance: Include extension in all imports (#2482)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Mar 14, 2023
1 parent 132582e commit 9d57220
Show file tree
Hide file tree
Showing 39 changed files with 90 additions and 86 deletions.
2 changes: 1 addition & 1 deletion __tests__/legacy-3.ts
Expand Up @@ -12,8 +12,8 @@ import {
SchemaDetail,
} from '@rest-hooks/endpoint';
import { rest3 } from '@rest-hooks/legacy';
import React from 'react';
import { SimpleRecord } from '@rest-hooks/legacy';
import React from 'react';

export const { Resource } = rest3;

Expand Down
4 changes: 2 additions & 2 deletions __tests__/legacy.ts
@@ -1,3 +1,5 @@
import { Endpoint, EndpointExtraOptions } from '@rest-hooks/endpoint';
import { schema } from '@rest-hooks/endpoint';
import {
MutateShape,
Resource,
Expand All @@ -9,8 +11,6 @@ import {
SimpleRecord,
} from '@rest-hooks/legacy';
import type { AbstractInstanceType } from '@rest-hooks/normalizr';
import { Endpoint, EndpointExtraOptions } from '@rest-hooks/endpoint';
import { schema } from '@rest-hooks/endpoint';
import React from 'react';

export class UserResource extends Resource {
Expand Down
1 change: 1 addition & 0 deletions babel.config.js
Expand Up @@ -13,6 +13,7 @@ module.exports = function (api) {
loose: true,
resolver: {
resolvePath(sourcePath, currentFile, opts) {
// babel needs to handle .js imports that refer to .ts files
if (
process.env.NODE_ENV === 'test' &&
sourcePath.startsWith('.') &&
Expand Down
4 changes: 2 additions & 2 deletions examples/nextjs/package.json
Expand Up @@ -9,8 +9,8 @@
"lint": "next lint"
},
"dependencies": {
"@rest-hooks/react": "^7.1.3",
"@rest-hooks/redux": "^6.2.2",
"@rest-hooks/react": "^7.2.6",
"@rest-hooks/redux": "^6.3.3",
"@rest-hooks/rest": "^6.2.7",
"@rest-hooks/ssr": "^0.7.3",
"@rest-hooks/test": "^10.0.0",
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/controller/Controller.ts
Expand Up @@ -28,13 +28,11 @@ import {
createSubscription,
} from './createSubscription.js';
import type { EndpointUpdateFunction } from './types.js';
import { CompatibleActionTypes } from '../compatibleActions.js';
import { initialState } from '../state/reducer/createReducer.js';
import selectMeta from '../state/selectMeta.js';
import type {
ActionTypes as BroadActionTypes,
CombinedActionTypes,
legacyActions,
State,
} from '../types.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types.ts
Expand Up @@ -20,7 +20,7 @@ import { EndpointUpdateFunction } from './controller/types.js';
import * as legacyActions from './legacyActions.js';
import { Dispatch, Middleware, MiddlewareAPI } from './middlewareTypes.js';
import * as newActions from './newActions.js';
import * as previousActions from './previousActions';
import * as previousActions from './previousActions.js';

export type { AbstractInstanceType, UpdateFunction };

Expand Down
2 changes: 1 addition & 1 deletion packages/endpoint/src/schema.d.ts
Expand Up @@ -27,7 +27,7 @@ import {
IDClass,
Constructor,
PKClass,
} from './schemas/EntitySchema';
} from './schemas/EntitySchema.js';

export { Delete, EntityMap };

Expand Down
3 changes: 2 additions & 1 deletion packages/experimental/package.json
Expand Up @@ -26,6 +26,7 @@
]
}
},
"type": "module",
"engines": {
"node": "^12.17 || ^13.7 || >=14"
},
Expand All @@ -39,7 +40,7 @@
],
"scripts": {
"build:lib": "NODE_ENV=production BROWSERSLIST_ENV=2019 babel --root-mode upward src --out-dir lib --extensions '.ts,.tsx,.js' --ignore '**/__tests__/**' --ignore '**/*.d.ts'",
"build:bundle": "rollup -c",
"build:bundle": "rollup -c && echo '{\"type\":\"commonjs\"}' > dist/package.json",
"build:clean": "rimraf lib dist ts3.4 *.tsbuildinfo",
"build:legacy-types": "yarn run downlevel-dts lib ts3.4",
"build": "yarn run build:lib && yarn run build:bundle",
Expand Down
12 changes: 6 additions & 6 deletions packages/experimental/rollup.config.js
@@ -1,10 +1,10 @@
import commonjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import json from 'rollup-plugin-json';
import { terser } from 'rollup-plugin-terser';
import commonjs from 'rollup-plugin-commonjs';
import filesize from 'rollup-plugin-filesize';
import json from 'rollup-plugin-json';
import resolve from 'rollup-plugin-node-resolve';
import replace from 'rollup-plugin-replace';
import { terser } from 'rollup-plugin-terser';

import pkg from './package.json';

Expand All @@ -26,7 +26,7 @@ function isExternal(id) {
export default [
// browser-friendly UMD build
{
input: 'src/index.ts',
input: 'lib/index.js',
external: isExternal,
output: [{ file: pkg.unpkg, format: 'umd', name: 'restHookImg' }],
plugins: [
Expand All @@ -46,7 +46,7 @@ export default [
},
// node-friendly commonjs build
{
input: 'src/index.ts',
input: 'lib/index.js',
external: isExternal,
output: [{ file: pkg.main, format: 'cjs' }],
plugins: [
Expand Down
14 changes: 7 additions & 7 deletions packages/experimental/src/index.ts
@@ -1,12 +1,12 @@
export { Controller, useController } from '@rest-hooks/react';
export { default as useSubscription } from './hooks/useSubscription';
export { default as RestEndpoint } from './rest/RestEndpoint';
export * from './rest/RestEndpoint';
export { default as createResource } from './rest/createResource';
export type { Resource } from './rest/createResource';
export { default as paginationUpdate } from './rest/paginationUpdate';
export { default as useSubscription } from './hooks/useSubscription.js';
export { default as RestEndpoint } from './rest/RestEndpoint.js';
export * from './rest/RestEndpoint.js';
export { default as createResource } from './rest/createResource.js';
export type { Resource } from './rest/createResource.js';
export { default as paginationUpdate } from './rest/paginationUpdate.js';
import { schema, Entity, EndpointExtraOptions } from '@rest-hooks/endpoint';
const Delete = schema.Delete;
export { Delete, Entity };
export type { EndpointExtraOptions };
export * from './rest/types';
export * from './rest/types.js';
1 change: 1 addition & 0 deletions packages/experimental/src/package.json
@@ -0,0 +1 @@
{"type":"commonjs"}
2 changes: 1 addition & 1 deletion packages/experimental/src/rest/RestEndpoint.d.ts
Expand Up @@ -7,7 +7,7 @@ import type {
FetchFunction,
} from '@rest-hooks/endpoint';

import { PathArgs } from './types';
import { PathArgs } from './types.js';

export interface RestInstance<
F extends FetchFunction = FetchFunction,
Expand Down
8 changes: 4 additions & 4 deletions packages/experimental/src/rest/RestEndpoint.js
@@ -1,9 +1,9 @@
import { Endpoint } from '@rest-hooks/endpoint';

import NetworkError from './NetworkError';
import paginationUpdate from './paginationUpdate';
import paramsToString from './paramsToString';
import { getUrlBase, getUrlTokens, isPojo } from './RestHelpers';
import NetworkError from './NetworkError.js';
import paginationUpdate from './paginationUpdate.js';
import paramsToString from './paramsToString.js';
import { getUrlBase, getUrlTokens, isPojo } from './RestHelpers.js';

/** Simplifies endpoint definitions that follow REST patterns
*
Expand Down
2 changes: 1 addition & 1 deletion packages/experimental/src/rest/RestHelpers.ts
@@ -1,6 +1,6 @@
import { compile, PathFunction, parse } from 'path-to-regexp';

import { ShortenPath } from './types';
import { ShortenPath } from './types.js';

const urlBaseCache: Record<string, PathFunction<object>> = {};
export function getUrlBase(path: string): PathFunction {
Expand Down
6 changes: 3 additions & 3 deletions packages/experimental/src/rest/__tests__/Resource.test.ts
Expand Up @@ -5,8 +5,8 @@ import { act } from '@testing-library/react-hooks';
import nock from 'nock';

import { makeRenderRestHook } from '../../../../test';
import createResource from '../createResource';
import RestEndpoint from '../RestEndpoint';
import createResource from '../createResource.js';
import RestEndpoint from '../RestEndpoint.js';
import {
payload,
createPayload,
Expand All @@ -15,7 +15,7 @@ import {
moreNested,
paginatedFirstPage,
paginatedSecondPage,
} from '../test-fixtures';
} from '../test-fixtures.js';

export class User extends Entity {
readonly id: number | undefined = undefined;
Expand Down
4 changes: 2 additions & 2 deletions packages/experimental/src/rest/__tests__/RestEndpoint.ts
Expand Up @@ -9,7 +9,7 @@ import RestEndpoint, {
Defaults,
RestEndpointConstructorOptions,
RestGenerics,
} from '../RestEndpoint';
} from '../RestEndpoint.js';
import {
payload,
createPayload,
Expand All @@ -18,7 +18,7 @@ import {
moreNested,
paginatedFirstPage,
paginatedSecondPage,
} from '../test-fixtures';
} from '../test-fixtures.js';

export class User extends Entity {
readonly id: number | undefined = undefined;
Expand Down
Expand Up @@ -12,8 +12,8 @@ import { act } from '@testing-library/react-hooks';
import nock from 'nock';
import { useContext } from 'react';

import createResource from '../createResource';
import RestEndpoint, { RestGenerics } from '../RestEndpoint';
import createResource from '../createResource.js';
import RestEndpoint, { RestGenerics } from '../RestEndpoint.js';

describe('resource', () => {
const renderRestHook: ReturnType<typeof makeRenderRestHook> =
Expand Down
4 changes: 2 additions & 2 deletions packages/experimental/src/rest/__tests__/types.test.ts
@@ -1,5 +1,5 @@
import { GetEndpoint } from '../RestEndpoint';
import { PathArgs, ShortenPath } from '../types';
import { GetEndpoint } from '../RestEndpoint.js';
import { PathArgs, ShortenPath } from '../types.js';

describe('PathArgs', () => {
it('should infer types', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/experimental/src/rest/createResource.ts
Expand Up @@ -4,9 +4,9 @@ import RestEndpoint, {
GetEndpoint,
MutateEndpoint,
RestTypeNoBody,
} from './RestEndpoint';
import { shortenPath } from './RestHelpers';
import { PathArgs, ShortenPath } from './types';
} from './RestEndpoint.js';
import { shortenPath } from './RestHelpers.js';
import { PathArgs, ShortenPath } from './types.js';

const { Delete } = schema;

Expand Down
2 changes: 1 addition & 1 deletion packages/experimental/src/rest/paginationUpdate.ts
@@ -1,6 +1,6 @@
import { Schema } from '@rest-hooks/endpoint';

import getArrayPath from './getArrayPath';
import getArrayPath from './getArrayPath.js';

export default function paginationUpdate<
E extends { schema: Schema; key: any } & ((...args: any) => Promise<any>),
Expand Down
3 changes: 2 additions & 1 deletion packages/hooks/package.json
Expand Up @@ -26,6 +26,7 @@
]
}
},
"type": "module",
"files": [
"src",
"dist",
Expand All @@ -36,7 +37,7 @@
],
"scripts": {
"build:lib": "NODE_ENV=production BROWSERSLIST_ENV=2019 ROOT_PATH_PREFIX='@rest-hooks/hooks' babel --root-mode upward src --out-dir lib --extensions '.ts,.tsx,.js' --ignore '**/__tests__/**' --ignore '**/*.d.ts'",
"build:bundle": "rollup -c",
"build:bundle": "rollup -c && echo '{\"type\":\"commonjs\"}' > dist/package.json",
"build:clean": "rimraf lib dist ts3.4 *.tsbuildinfo",
"build": "yarn run build:lib && yarn run build:bundle",
"build:legacy-types": "yarn run downlevel-dts lib ts3.4",
Expand Down
15 changes: 7 additions & 8 deletions packages/hooks/rollup.config.js
@@ -1,11 +1,11 @@
import commonjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import json from 'rollup-plugin-json';
import { terser } from 'rollup-plugin-terser';
import commonjs from 'rollup-plugin-commonjs';
import dts from 'rollup-plugin-dts';
import filesize from 'rollup-plugin-filesize';
import json from 'rollup-plugin-json';
import resolve from 'rollup-plugin-node-resolve';
import replace from 'rollup-plugin-replace';
import dts from 'rollup-plugin-dts';
import { terser } from 'rollup-plugin-terser';

import pkg from './package.json';

Expand All @@ -17,7 +17,6 @@ const extensions = ['.js', '.ts', '.tsx', '.mjs', '.json', '.node'];
const nativeExtensions = ['.native.ts', ...extensions];
process.env.NODE_ENV = 'production';
process.env.BROWSERSLIST_ENV = 'legacy';
process.env.ROOT_PATH_PREFIX = '@rest-hooks/hooks';

function isExternal(id) {
const ret = dependencies.includes(id);
Expand All @@ -32,7 +31,7 @@ function isExternal(id) {
export default [
// browser-friendly UMD build
{
input: 'src/index.ts',
input: 'lib/index.js',
external: isExternal,
output: [{ file: pkg.unpkg, format: 'umd', name: 'restHookHooks' }],
plugins: [
Expand All @@ -57,7 +56,7 @@ export default [
},
// node-friendly commonjs build
{
input: 'src/index.ts',
input: 'lib/index.js',
external: isExternal,
output: [{ file: pkg.main, format: 'cjs' }],
plugins: [
Expand Down
6 changes: 3 additions & 3 deletions packages/hooks/src/index.ts
@@ -1,3 +1,3 @@
export { default as useDebounce } from './useDebounce';
export { default as useCancelling } from './useCancelling';
export { default as useLoading } from './useLoading';
export { default as useDebounce } from './useDebounce.js';
export { default as useCancelling } from './useCancelling.js';
export { default as useLoading } from './useLoading.js';
3 changes: 2 additions & 1 deletion packages/img/package.json
Expand Up @@ -26,6 +26,7 @@
]
}
},
"type": "module",
"files": [
"src",
"dist",
Expand All @@ -36,7 +37,7 @@
],
"scripts": {
"build:lib": "NODE_ENV=production BROWSERSLIST_ENV=2019 babel --root-mode upward src --out-dir lib --extensions '.ts,.tsx,.js' --ignore '**/__tests__/**' --ignore '**/*.d.ts'",
"build:bundle": "rollup -c",
"build:bundle": "rollup -c && echo '{\"type\":\"commonjs\"}' > dist/package.json",
"build:clean": "rimraf lib dist ts3.4 *.tsbuildinfo",
"build:legacy-types": "yarn run downlevel-dts lib ts3.4",
"build": "yarn run build:lib && yarn run build:bundle",
Expand Down
13 changes: 6 additions & 7 deletions packages/img/rollup.config.js
@@ -1,10 +1,10 @@
import commonjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import json from 'rollup-plugin-json';
import { terser } from 'rollup-plugin-terser';
import commonjs from 'rollup-plugin-commonjs';
import filesize from 'rollup-plugin-filesize';
import json from 'rollup-plugin-json';
import resolve from 'rollup-plugin-node-resolve';
import replace from 'rollup-plugin-replace';
import { terser } from 'rollup-plugin-terser';

import pkg from './package.json';

Expand All @@ -16,7 +16,6 @@ const extensions = ['.js', '.ts', '.tsx', '.mjs', '.json', '.node'];
const nativeExtensions = ['.native.ts', ...extensions];
process.env.NODE_ENV = 'production';
process.env.BROWSERSLIST_ENV = 'legacy';
process.env.ROOT_PATH_PREFIX = '@rest-hooks/img';

function isExternal(id) {
return dependencies.some(dep => dep === id || id.startsWith(dep));
Expand All @@ -25,7 +24,7 @@ function isExternal(id) {
export default [
// browser-friendly UMD build
{
input: 'src/index.ts',
input: 'lib/index.js',
external: isExternal,
output: [{ file: pkg.unpkg, format: 'umd', name: 'restHookImg' }],
plugins: [
Expand All @@ -45,7 +44,7 @@ export default [
},
// node-friendly commonjs build
{
input: 'src/index.ts',
input: 'lib/index.js',
external: isExternal,
output: [{ file: pkg.main, format: 'cjs' }],
plugins: [
Expand Down
2 changes: 1 addition & 1 deletion packages/img/src/Img.tsx
@@ -1,7 +1,7 @@
import { useSuspense } from '@rest-hooks/react';
import React from 'react';

import getImage from './getImage';
import getImage from './getImage.js';

type Props<
C extends
Expand Down
4 changes: 2 additions & 2 deletions packages/img/src/index.ts
@@ -1,2 +1,2 @@
export { default as Img } from './Img';
export { default as getImage } from './getImage';
export { default as Img } from './Img.js';
export { default as getImage } from './getImage.js';

1 comment on commit 9d57220

@vercel
Copy link

@vercel vercel bot commented on 9d57220 Mar 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.