Skip to content

Commit 55f25f8

Browse files
committed
#270 rename all JS imports to use filenames
1 parent d3232a6 commit 55f25f8

30 files changed

+85
-66
lines changed

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ module.exports = {
44
extends: [
55
'eslint:recommended',
66
'plugin:prettier/recommended',
7+
"plugin:import/recommended",
8+
"plugin:import/typescript",
79
'plugin:react/recommended', // Uses the recommended rules from @eslint-plugin-react
810
'plugin:@typescript-eslint/eslint-recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
911
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
@@ -50,6 +52,8 @@ module.exports = {
5052
'comma-dangle': 'off', // https://eslint.org/docs/rules/comma-dangle
5153
'function-paren-newline': 'off', // https://eslint.org/docs/rules/function-paren-newline
5254
'global-require': 'off', // https://eslint.org/docs/rules/global-require
55+
"import/extensions": ["error", "ignorePackages"],
56+
"import/no-unresolved": "off",
5357
'import/no-dynamic-require': 'off', // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-dynamic-require.md
5458
'no-inner-declarations': 'off', // https://eslint.org/docs/rules/no-inner-declarations// New rules
5559
'class-methods-use-this': 'off',

CONTRIBUTE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ Talk with other devs on our [Discord][discord-url]!
2121
- `pnpm publish -r`
2222
- Choose a new version. Versions should match `atomic-data-rs`.
2323
- This updates the `package.json` files, creates a commit, tags it, pushes it to github, and publishes the builds to npm.
24-
- If this fails, try `pnpm version patch` and `pnpm npm publish`
24+
- If this fails, try `pnpm version patch` and `pnpm publish`
25+
- DONT run `pnpm npm publish`, as it will not resolve workspace dependencies correctly.
2526

2627
## Understanding vite and pnpm workspaces
2728

lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.34.1",
2+
"version": "0.34.5",
33
"author": "Joep Meindertsma",
44
"dependencies": {
55
"@noble/ed25519": "1.6.0",

lib/src/EventManager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EventManager } from './EventManager';
1+
import { EventManager } from './EventManager.js';
22
enum Events {
33
Click = 'click',
44
LotteryWon = 'lotterywon',

lib/src/agent.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from 'chai';
2-
import { Agent } from './index';
2+
import { Agent } from './index.js';
33

44
describe('Agent', () => {
55
it('Constructs valid ', async () => {

lib/src/agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
generatePublicKeyFromPrivate,
55
properties,
66
tryValidURL,
7-
} from './index';
7+
} from './index.js';
88

99
/**
1010
* An Agent is a user or machine that can write data to an Atomic Server. An

lib/src/authentication.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Agent, getTimestampNow, HeadersObject, signToBase64, Store } from '.';
1+
import {
2+
Agent,
3+
getTimestampNow,
4+
HeadersObject,
5+
signToBase64,
6+
Store,
7+
} from './index.js';
28

39
/** Returns a JSON-AD resource of an Authentication */
410
export async function createAuthentication(subject: string, agent: Agent) {

lib/src/class.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
Property,
88
Resource,
99
Store,
10-
} from './index';
10+
} from './index.js';
1111

1212
/** Returns the Typescript interface string based on the Class */
1313
export async function classToTypescriptDefinition(

lib/src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
setCookieAuthentication,
1515
signRequest,
1616
Store,
17-
} from './index';
17+
} from './index.js';
1818

1919
/** Works both in node and the browser */
2020
import fetch from 'cross-fetch';

lib/src/commit.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { expect } from 'chai';
2-
import { CommitBuilder } from './commit';
2+
import { CommitBuilder } from './commit.js';
33
import {
44
generatePublicKeyFromPrivate,
55
parseAndApplyCommit,
66
serializeDeterministically,
77
signToBase64,
88
Store,
9-
} from './index';
9+
} from './index.js';
1010

1111
// These are disabled for now, as they require TextEncoder to be available
1212
// https://github.com/facebook/jest/issues/9983

lib/src/commit.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ import { decode as decodeB64, encode as encodeB64 } from 'base64-arraybuffer';
66
import { sha512 } from '@noble/hashes/sha512';
77
utils.sha512 = msg => Promise.resolve(sha512(msg));
88

9-
import { properties, urls } from './urls';
10-
import { Store } from './store';
119
import {
1210
isArray,
1311
JSONArray,
1412
JSONValue,
1513
parseJsonAdResourceValue,
1614
removeQueryParamsFromURL,
1715
Resource,
18-
} from './index';
16+
properties,
17+
urls,
18+
Store,
19+
} from './index.js';
1920

2021
/** A {@link Commit} without its signature, signer and timestamp */
2122
export interface CommitBuilderI {

lib/src/datatypes.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from 'chai';
2-
import { Datatype, urls, validateDatatype } from './index';
2+
import { Datatype, urls, validateDatatype } from './index.js';
33

44
describe('Datatypes', () => {
55
it('throws errors when datatypes dont match values', async () => {

lib/src/datatypes.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { urls } from './urls';
2-
import { tryValidURL } from './client';
3-
import { JSONValue } from './value';
1+
import { JSONValue, tryValidURL, urls } from './index.js';
42

53
/** Each possible Atomic Datatype. See https://atomicdata.dev/collections/datatype */
64
// TODO: use strings from `./urls`, requires TS fix: https://github.com/microsoft/TypeScript/issues/40793

lib/src/error.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Resource } from './resource';
2-
import { properties } from './urls';
1+
import { Resource, properties } from './index.js';
32

43
export enum ErrorType {
54
Unauthorized = 'Unauthorized',

lib/src/index.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@
2929
* @module
3030
*/
3131

32-
export * from './agent';
33-
export * from './authentication';
34-
export * from './class';
35-
export * from './client';
36-
export * from './commit';
37-
export * from './error';
38-
export * from './datatypes';
39-
export * from './parse';
40-
export * from './resource';
41-
export * from './store';
42-
export * from './value';
43-
export * from './urls';
44-
export * from './truncate';
32+
export * from './agent.js';
33+
export * from './authentication.js';
34+
export * from './class.js';
35+
export * from './client.js';
36+
export * from './commit.js';
37+
export * from './error.js';
38+
export * from './datatypes.js';
39+
export * from './parse.js';
40+
export * from './resource.js';
41+
export * from './store.js';
42+
export * from './value.js';
43+
export * from './urls.js';
44+
export * from './truncate.js';

lib/src/parse.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import { AtomicError } from './error';
2-
import { urls } from './urls';
3-
import { isArray, JSONValue, Store } from './index';
4-
import { Resource, unknownSubject } from './resource';
5-
import { JSONObject } from './value';
1+
import {
2+
AtomicError,
3+
urls,
4+
isArray,
5+
JSONValue,
6+
JSONObject,
7+
Store,
8+
Resource,
9+
unknownSubject,
10+
} from './index.js';
611

712
/**
813
* Parses an JSON-AD object containing a resource, adds it to the input

lib/src/resource.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { instances } from './urls';
21
import {
32
Agent,
43
CommitBuilder,
@@ -11,8 +10,9 @@ import {
1110
tryValidURL,
1211
validateDatatype,
1312
valToArray,
14-
} from './index';
15-
import { JSONArray } from './value';
13+
instances,
14+
JSONArray,
15+
} from './index.js';
1616

1717
/** Contains the PropertyURL / Value combinations */
1818
export type PropVals = Map<string, JSONValue>;

lib/src/store.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from 'chai';
2-
import { Resource, urls, Store } from './index';
2+
import { Resource, urls, Store } from './index.js';
33

44
describe('Store', () => {
55
it('renders the populate value', async () => {

lib/src/store.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { setCookieAuthentication } from './authentication';
2-
import { EventManager } from './EventManager';
1+
import { setCookieAuthentication } from './authentication.js';
2+
import { EventManager } from './EventManager.js';
33
import {
44
Agent,
55
Datatype,
@@ -9,8 +9,8 @@ import {
99
tryValidURL,
1010
unknownSubject,
1111
urls,
12-
} from './index';
13-
import { authenticate, fetchWebSocket, startWebsocket } from './websockets';
12+
} from './index.js';
13+
import { authenticate, fetchWebSocket, startWebsocket } from './websockets.js';
1414

1515
/** Function called when a resource is updated or removed */
1616
type Callback = (resource: Resource) => void;

lib/src/value.ts

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

33
export type JSONPrimitive = string | number | boolean;
44
export type JSONValue = JSONPrimitive | JSONObject | JSONArray | undefined;

lib/src/websockets.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { createAuthentication } from './authentication';
1+
import { createAuthentication } from './authentication.js';
22
import {
33
parseAndApplyCommit,
44
parseJsonADResource,
55
Resource,
66
Store,
77
unknownSubject,
8-
} from './index';
8+
} from './index.js';
99

1010
/** Opens a Websocket Connection at `/ws` for the current Drive */
1111
export function startWebsocket(url: string, store: Store): WebSocket {

react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.34.1",
2+
"version": "0.34.8",
33
"author": "Joep Meindertsma",
44
"description": "Atomic Data React library",
55
"dependencies": {

react/src/hooks.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { useState, useEffect, useCallback, useMemo, useRef } from 'react';
1+
import React, {
2+
useState,
3+
useEffect,
4+
useCallback,
5+
useMemo,
6+
useRef,
7+
} from 'react';
28
import {
39
Property,
410
Store,
@@ -17,8 +23,7 @@ import {
1723
unknownSubject,
1824
JSONArray,
1925
} from '@tomic/lib';
20-
import React from 'react';
21-
import { useDebounce } from './index';
26+
import { useDebounce } from './index.js';
2227

2328
/**
2429
* Hook for getting a Resource in a React component. Will try to fetch the

react/src/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
* @module
2323
*/
2424

25-
export * from './hooks';
26-
export * from './useServerURL';
27-
export * from './useCurrentAgent';
28-
export * from './useDebounce';
29-
export * from './useImporter';
30-
export * from './useLocalStorage';
31-
export * from './useMarkdown';
32-
export * from './useServerSearch';
25+
export * from './hooks.js';
26+
export * from './useServerURL.js';
27+
export * from './useCurrentAgent.js';
28+
export * from './useDebounce.js';
29+
export * from './useImporter.js';
30+
export * from './useLocalStorage.js';
31+
export * from './useMarkdown.js';
32+
export * from './useServerSearch.js';
3333
export * from '@tomic/lib';

react/src/useCurrentAgent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useCallback, useEffect, useState } from 'react';
22
import { Agent } from '@tomic/lib';
3-
import { useLocalStorage, useStore } from './index';
3+
import { useLocalStorage, useStore } from './index.js';
44

55
const AGENT_LOCAL_STORAGE_KEY = 'agent';
66

react/src/useImporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { useResource } from './';
21
import { useEffect, useState } from 'react';
2+
import { useResource } from './index.js';
33

44
/** Easily send JSON-AD or a URL containing it to your server. */
55
export function useImporter(importerUrl?: string) {

react/src/useMarkdown.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
valToDate,
1010
} from '@tomic/lib';
1111
import { useEffect, useState } from 'react';
12-
import { useStore, useString, useTitle } from './index';
12+
import { useStore, useString, useTitle } from './index.js';
1313

1414
/** Properties not relevant to show in PropValLines */
1515
const hiddenProps = [

react/src/useServerSearch.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { urls } from '@tomic/lib';
22
import { useEffect, useMemo, useState } from 'react';
3-
import { useArray, useDebounce, useResource, useStore } from './index';
3+
import { useArray, useDebounce, useResource, useStore } from './index.js';
44

55
interface SearchResults {
66
/** Subject URLs for resources that match the query */

react/src/useServerURL.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isValidURL } from '@tomic/lib';
22
import { useCallback } from 'react';
3-
import { useLocalStorage, useStore } from './index';
3+
import { useLocalStorage, useStore } from './index.js';
44

55
/**
66
* A hook for using and adjusting the Server URL. Also saves to localStorage. If

tsconfig.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "ES5",
4-
"module": "commonjs",
4+
"module": "ES2022",
55
"lib": [
66
"ES6",
77
"ES7",

0 commit comments

Comments
 (0)