Skip to content

Commit 5f7c6c3

Browse files
committed
Add extensions to imports
1 parent 9a5eb36 commit 5f7c6c3

40 files changed

+120
-108
lines changed

eslint.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ const config = tsEslint.config([
133133
'jsx-a11y/anchor-is-valid': 'off',
134134
},
135135
},
136+
{
137+
files: ['node_package/**/*'],
138+
rules: {
139+
'import/extensions': ['error', 'ignorePackages'],
140+
},
141+
},
136142
{
137143
files: ['lib/generators/react_on_rails/templates/**/*'],
138144
rules: {

node_package/src/Authenticity.ts

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

33
export function authenticityToken(): string | null {
44
const token = document.querySelector('meta[name="csrf-token"]');

node_package/src/CallbackRegistry.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ItemRegistrationCallback } from './types';
2-
import { onPageLoaded, onPageUnloaded } from './pageLifecycle';
3-
import { getRailsContext } from './context';
1+
import { ItemRegistrationCallback } from './types/index.ts';
2+
import { onPageLoaded, onPageUnloaded } from './pageLifecycle.ts';
3+
import { getRailsContext } from './context.ts';
44

55
/**
66
* Represents information about a registered item including its value,

node_package/src/ClientSideRenderer.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33

44
import * as ReactDOM from 'react-dom';
55
import type { ReactElement } from 'react';
6-
import type { RailsContext, RegisteredComponent, RenderFunction, Root } from './types';
7-
8-
import { getRailsContext, resetRailsContext } from './context';
9-
import createReactOutput from './createReactOutput';
10-
import { isServerRenderHash } from './isServerRenderResult';
11-
import reactHydrateOrRender from './reactHydrateOrRender';
12-
import { supportsRootApi } from './reactApis';
13-
import { debugTurbolinks } from './turbolinksUtils';
14-
import * as StoreRegistry from './StoreRegistry';
15-
import * as ComponentRegistry from './ComponentRegistry';
6+
import type { RailsContext, RegisteredComponent, RenderFunction, Root } from './types/index.ts';
7+
8+
import { getRailsContext, resetRailsContext } from './context.ts';
9+
import createReactOutput from './createReactOutput.ts';
10+
import { isServerRenderHash } from './isServerRenderResult.ts';
11+
import reactHydrateOrRender from './reactHydrateOrRender.ts';
12+
import { supportsRootApi } from './reactApis.ts';
13+
import { debugTurbolinks } from './turbolinksUtils.ts';
14+
import * as StoreRegistry from './StoreRegistry.ts';
15+
import * as ComponentRegistry from './ComponentRegistry.ts';
1616

1717
const REACT_ON_RAILS_STORE_ATTRIBUTE = 'data-js-react-on-rails-store';
1818

node_package/src/ComponentRegistry.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { type RegisteredComponent, type ReactComponentOrRenderFunction } from './types';
2-
import isRenderFunction from './isRenderFunction';
3-
import CallbackRegistry from './CallbackRegistry';
1+
import { type RegisteredComponent, type ReactComponentOrRenderFunction } from './types/index.ts';
2+
import isRenderFunction from './isRenderFunction.ts';
3+
import CallbackRegistry from './CallbackRegistry.ts';
44

55
const componentRegistry = new CallbackRegistry<RegisteredComponent>('component');
66

node_package/src/RSCClientRoot.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import * as React from 'react';
44
import * as ReactDOMClient from 'react-dom/client';
55
import { createFromReadableStream } from 'react-on-rails-rsc/client';
6-
import { fetch } from './utils';
7-
import transformRSCStreamAndReplayConsoleLogs from './transformRSCStreamAndReplayConsoleLogs';
8-
import { RailsContext, RenderFunction } from './types';
6+
import { fetch } from './utils.ts';
7+
import transformRSCStreamAndReplayConsoleLogs from './transformRSCStreamAndReplayConsoleLogs.ts';
8+
import { RailsContext, RenderFunction } from './types/index.ts';
99

1010
const { use } = React;
1111

node_package/src/ReactOnRails.client.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { ReactElement } from 'react';
2-
import * as ClientStartup from './clientStartup';
3-
import { renderOrHydrateComponent, hydrateStore } from './ClientSideRenderer';
4-
import * as ComponentRegistry from './ComponentRegistry';
5-
import * as StoreRegistry from './StoreRegistry';
6-
import buildConsoleReplay from './buildConsoleReplay';
7-
import createReactOutput from './createReactOutput';
8-
import * as Authenticity from './Authenticity';
2+
import * as ClientStartup from './clientStartup.ts';
3+
import { renderOrHydrateComponent, hydrateStore } from './ClientSideRenderer.ts';
4+
import * as ComponentRegistry from './ComponentRegistry.ts';
5+
import * as StoreRegistry from './StoreRegistry.ts';
6+
import buildConsoleReplay from './buildConsoleReplay.ts';
7+
import createReactOutput from './createReactOutput.ts';
8+
import * as Authenticity from './Authenticity.ts';
99
import type {
1010
RegisteredComponent,
1111
RenderResult,
@@ -15,8 +15,8 @@ import type {
1515
Store,
1616
StoreGenerator,
1717
ReactOnRailsOptions,
18-
} from './types';
19-
import reactHydrateOrRender from './reactHydrateOrRender';
18+
} from './types/index.ts';
19+
import reactHydrateOrRender from './reactHydrateOrRender.ts';
2020

2121
if (globalThis.ReactOnRails !== undefined) {
2222
throw new Error(`\
@@ -194,5 +194,5 @@ globalThis.ReactOnRails.resetOptions();
194194

195195
ClientStartup.clientStartup();
196196

197-
export * from './types';
197+
export * from './types/index.ts';
198198
export default globalThis.ReactOnRails;

node_package/src/ReactOnRails.full.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import handleError from './handleError';
2-
import serverRenderReactComponent from './serverRenderReactComponent';
3-
import type { RenderParams, RenderResult, ErrorOptions } from './types';
1+
import handleError from './handleError.ts';
2+
import serverRenderReactComponent from './serverRenderReactComponent.ts';
3+
import type { RenderParams, RenderResult, ErrorOptions } from './types/index.ts';
44

5-
import Client from './ReactOnRails.client';
5+
import Client from './ReactOnRails.client.ts';
66

77
if (typeof window !== 'undefined') {
88
console.log(
@@ -15,5 +15,5 @@ Client.handleError = (options: ErrorOptions): string | undefined => handleError(
1515
Client.serverRenderReactComponent = (options: RenderParams): null | string | Promise<RenderResult> =>
1616
serverRenderReactComponent(options);
1717

18-
export * from './types';
18+
export * from './types/index.ts';
1919
export default Client;

node_package/src/ReactOnRails.node.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import ReactOnRails from './ReactOnRails.full';
2-
import streamServerRenderedReactComponent from './streamServerRenderedReactComponent';
1+
import ReactOnRails from './ReactOnRails.full.ts';
2+
import streamServerRenderedReactComponent from './streamServerRenderedReactComponent.ts';
33

44
ReactOnRails.streamServerRenderedReactComponent = streamServerRenderedReactComponent;
55

6-
export * from './ReactOnRails.full';
6+
export * from './ReactOnRails.full.ts';
77
// eslint-disable-next-line no-restricted-exports -- see https://github.com/eslint/eslint/issues/15617
8-
export { default } from './ReactOnRails.full';
8+
export { default } from './ReactOnRails.full.ts';

node_package/src/ReactOnRailsRSC.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { renderToPipeableStream } from 'react-on-rails-rsc/server.node';
22
import { PassThrough, Readable } from 'stream';
33

4-
import { RSCRenderParams, StreamRenderState, StreamableComponentResult } from './types';
5-
import ReactOnRails from './ReactOnRails.full';
6-
import buildConsoleReplay from './buildConsoleReplay';
7-
import handleError from './handleError';
8-
import { convertToError, createResultObject } from './serverRenderUtils';
4+
import { RSCRenderParams, StreamRenderState, StreamableComponentResult } from './types/index.ts';
5+
import ReactOnRails from './ReactOnRails.full.ts';
6+
import buildConsoleReplay from './buildConsoleReplay.ts';
7+
import handleError from './handleError.ts';
8+
import { convertToError, createResultObject } from './serverRenderUtils.ts';
99

1010
import {
1111
streamServerRenderedComponent,
1212
transformRenderStreamChunksToResultObject,
13-
} from './streamServerRenderedReactComponent';
14-
import loadReactClientManifest from './loadReactClientManifest';
13+
} from './streamServerRenderedReactComponent.ts';
14+
import loadReactClientManifest from './loadReactClientManifest.ts';
1515

1616
const stringToStream = (str: string) => {
1717
const stream = new PassThrough();
@@ -67,5 +67,5 @@ ReactOnRails.serverRenderRSCReactComponent = (options: RSCRenderParams) => {
6767
}
6868
};
6969

70-
export * from './types';
70+
export * from './types/index.ts';
7171
export default ReactOnRails;

node_package/src/StoreRegistry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import CallbackRegistry from './CallbackRegistry';
2-
import type { Store, StoreGenerator } from './types';
1+
import CallbackRegistry from './CallbackRegistry.ts';
2+
import type { Store, StoreGenerator } from './types/index.ts';
33

44
const storeGeneratorRegistry = new CallbackRegistry<StoreGenerator>('store generator');
55
const hydratedStoreRegistry = new CallbackRegistry<Store>('hydrated store');

node_package/src/buildConsoleReplay.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { wrapInScriptTags } from './RenderUtils';
2-
import scriptSanitizedVal from './scriptSanitizedVal';
1+
import { wrapInScriptTags } from './RenderUtils.ts';
2+
import scriptSanitizedVal from './scriptSanitizedVal.ts';
33

44
declare global {
55
interface Console {

node_package/src/clientStartup.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import {
44
renderOrHydrateAllComponents,
55
renderOrHydrateForceLoadedComponents,
66
unmountAll,
7-
} from './ClientSideRenderer';
8-
import { onPageLoaded, onPageUnloaded } from './pageLifecycle';
9-
import { debugTurbolinks } from './turbolinksUtils';
7+
} from './ClientSideRenderer.ts';
8+
import { onPageLoaded, onPageUnloaded } from './pageLifecycle.ts';
9+
import { debugTurbolinks } from './turbolinksUtils.ts';
1010

1111
export async function reactOnRailsPageLoaded() {
1212
debugTurbolinks('reactOnRailsPageLoaded');

node_package/src/context.ts

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

33
declare global {
44
/* eslint-disable no-var,vars-on-top,no-underscore-dangle */

node_package/src/createReactOutput.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
2-
import type { CreateParams, ReactComponent, RenderFunction, CreateReactOutputResult } from './types/index';
3-
import { isServerRenderHash, isPromise } from './isServerRenderResult';
2+
import type { CreateParams, ReactComponent, RenderFunction, CreateReactOutputResult } from './types/index.ts';
3+
import { isServerRenderHash, isPromise } from './isServerRenderResult.ts';
44

55
function createReactElementFromRenderFunctionResult(
66
renderFunctionResult: ReactComponent,

node_package/src/handleError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import * as ReactDOMServer from 'react-dom/server';
3-
import type { ErrorOptions } from './types/index';
3+
import type { ErrorOptions } from './types/index.ts';
44

55
function handleRenderFunctionIssue(options: ErrorOptions): string {
66
const { e, name } = options;

node_package/src/isRenderFunction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// See discussion:
22
// https://discuss.reactjs.org/t/how-to-determine-if-js-object-is-react-component/2825/2
3-
import { ReactComponentOrRenderFunction, RenderFunction } from './types/index';
3+
import { ReactComponentOrRenderFunction, RenderFunction } from './types/index.ts';
44

55
/**
66
* Used to determine we'll call be calling React.createElement on the component of if this is a

node_package/src/isServerRenderResult.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {
33
ServerRenderResult,
44
RenderFunctionResult,
55
RenderStateHtml,
6-
} from './types/index';
6+
} from './types/index.ts';
77

88
export function isServerRenderHash(
99
testValue: CreateReactOutputResult | RenderFunctionResult,

node_package/src/pageLifecycle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
turbolinksSupported,
55
turboInstalled,
66
turbolinksVersion5,
7-
} from './turbolinksUtils';
7+
} from './turbolinksUtils.ts';
88

99
type PageLifecycleCallback = () => void | Promise<void>;
1010
type PageState = 'load' | 'unload' | 'initial';

node_package/src/reactHydrateOrRender.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ReactElement } from 'react';
22
import * as ReactDOM from 'react-dom';
3-
import type { RenderReturnType } from './types';
4-
import { supportsRootApi } from './reactApis';
3+
import type { RenderReturnType } from './types/index.ts';
4+
import { supportsRootApi } from './reactApis.ts';
55

66
type HydrateOrRenderType = (domNode: Element, reactElement: ReactElement) => RenderReturnType;
77

node_package/src/registerServerComponent/client.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import ReactOnRails from '../ReactOnRails.client';
2-
import RSCClientRoot from '../RSCClientRoot';
3-
import { RegisterServerComponentOptions, RailsContext, ReactComponentOrRenderFunction } from '../types';
1+
import ReactOnRails from '../ReactOnRails.client.ts';
2+
import RSCClientRoot from '../RSCClientRoot.ts';
3+
import {
4+
RegisterServerComponentOptions,
5+
RailsContext,
6+
ReactComponentOrRenderFunction,
7+
} from '../types/index.ts';
48

59
/**
610
* Registers React Server Components (RSC) with React on Rails.

node_package/src/registerServerComponent/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import ReactOnRails from '../ReactOnRails.client';
2-
import { ReactComponent } from '../types';
1+
import ReactOnRails from '../ReactOnRails.client.ts';
2+
import { ReactComponent } from '../types/index.ts';
33

44
/**
55
* Registers React Server Components (RSC) with React on Rails for both server and RSC bundles.

node_package/src/serverRenderReactComponent.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import * as React from 'react';
22
import * as ReactDOMServer from 'react-dom/server';
33
import type { ReactElement } from 'react';
44

5-
import * as ComponentRegistry from './ComponentRegistry';
6-
import createReactOutput from './createReactOutput';
7-
import { isPromise, isServerRenderHash } from './isServerRenderResult';
8-
import buildConsoleReplay from './buildConsoleReplay';
9-
import handleError from './handleError';
10-
import { createResultObject, convertToError, validateComponent } from './serverRenderUtils';
5+
import * as ComponentRegistry from './ComponentRegistry.ts';
6+
import createReactOutput from './createReactOutput.ts';
7+
import { isPromise, isServerRenderHash } from './isServerRenderResult.ts';
8+
import buildConsoleReplay from './buildConsoleReplay.ts';
9+
import handleError from './handleError.ts';
10+
import { createResultObject, convertToError, validateComponent } from './serverRenderUtils.ts';
1111
import type {
1212
CreateReactOutputResult,
1313
RenderParams,
@@ -17,7 +17,7 @@ import type {
1717
ServerRenderResult,
1818
CreateReactOutputAsyncResult,
1919
RenderStateHtml,
20-
} from './types';
20+
} from './types/index.ts';
2121

2222
function processServerRenderHash(result: ServerRenderResult, options: RenderOptions): RenderState {
2323
const { redirectLocation, routeError } = result;

node_package/src/serverRenderUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
RenderState,
55
StreamRenderState,
66
FinalHtmlResult,
7-
} from './types';
7+
} from './types/index.ts';
88

99
export function createResultObject(
1010
html: FinalHtmlResult | null,

node_package/src/streamServerRenderedReactComponent.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import * as React from 'react';
22
import * as ReactDOMServer from 'react-dom/server';
33
import { PassThrough, Readable } from 'stream';
44

5-
import * as ComponentRegistry from './ComponentRegistry';
6-
import createReactOutput from './createReactOutput';
7-
import { isPromise, isServerRenderHash } from './isServerRenderResult';
8-
import buildConsoleReplay from './buildConsoleReplay';
9-
import handleError from './handleError';
10-
import { createResultObject, convertToError, validateComponent } from './serverRenderUtils';
11-
import type { RenderParams, StreamRenderState, StreamableComponentResult } from './types';
5+
import * as ComponentRegistry from './ComponentRegistry.ts';
6+
import createReactOutput from './createReactOutput.ts';
7+
import { isPromise, isServerRenderHash } from './isServerRenderResult.ts';
8+
import buildConsoleReplay from './buildConsoleReplay.ts';
9+
import handleError from './handleError.ts';
10+
import { createResultObject, convertToError, validateComponent } from './serverRenderUtils.ts';
11+
import type { RenderParams, StreamRenderState, StreamableComponentResult } from './types/index.ts';
1212

1313
type BufferedEvent = {
1414
event: 'data' | 'error' | 'end';

node_package/src/transformRSCStreamAndReplayConsoleLogs.ts

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

33
export default function transformRSCStreamAndReplayConsoleLogs(stream: ReadableStream<Uint8Array>) {
44
return new ReadableStream({

node_package/tests/Authenticity.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ReactOnRails from '../src/ReactOnRails.client';
1+
import ReactOnRails from '../src/ReactOnRails.client.ts';
22

33
const testToken = 'TEST_CSRF_TOKEN';
44

node_package/tests/ComponentRegistry.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import * as React from 'react';
77
import * as createReactClass from 'create-react-class';
88

9-
import * as ComponentRegistry from '../src/ComponentRegistry';
9+
import * as ComponentRegistry from '../src/ComponentRegistry.ts';
1010

1111
const onPageLoadedCallbacks = [];
1212
const onPageUnloadedCallbacks = [];
1313

14-
jest.mock('../src/pageLifecycle', () => ({
14+
jest.mock('../src/pageLifecycle.ts', () => ({
1515
onPageLoaded: jest.fn((cb) => {
1616
onPageLoadedCallbacks.push(cb);
1717
cb();
@@ -22,7 +22,7 @@ jest.mock('../src/pageLifecycle', () => ({
2222
}),
2323
}));
2424

25-
jest.mock('../src/context', () => ({
25+
jest.mock('../src/context.ts', () => ({
2626
getRailsContext: () => ({ componentRegistryTimeout: 100 }),
2727
}));
2828

0 commit comments

Comments
 (0)