Skip to content

Commit

Permalink
Split papi.d.ts (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
irahopkinson authored Jun 20, 2023
1 parent 4f19643 commit 6b5a007
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 19 deletions.
9 changes: 8 additions & 1 deletion extensions/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
module.exports = {
extends: '../.eslintrc.js',
rules: {
strict: 'off',
'import/no-unresolved': ['error', { ignore: ['papi'] }],
},
overrides: [
{
files: ['*.js'],
rules: {
strict: 'off',
},
},
],
settings: {
'import/resolver': {
// See https://github.com/benmosher/eslint-plugin-import/issues/1396#issuecomment-575727774 for line below
Expand Down
2 changes: 1 addition & 1 deletion extensions/lib/evil/evil.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'use strict';

// eslint-disable-next-line import/no-unresolved
const papi = require('papi');
const papi = require('papi-backend');

const { logger } = papi;

Expand Down
2 changes: 1 addition & 1 deletion extensions/lib/hello-someone/hello-someone.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import papi from 'papi';
import papi from 'papi-backend';
import type {
WebViewContentType,
WebViewDefinition,
Expand Down
2 changes: 1 addition & 1 deletion extensions/lib/hello-world/hello-world.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import papi from 'papi';
import papi from 'papi-backend';
import { UnsubscriberAsync } from 'shared/utils/papi-util';
import type {
WebViewContentType,
Expand Down
2 changes: 1 addition & 1 deletion extensions/lib/hello-world/hello-world.web-view.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import papi from 'papi';
import papi from 'papi-frontend';
import {
Button,
Checkbox,
Expand Down
2 changes: 1 addition & 1 deletion extensions/lib/quick-verse/quick-verse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import papi from 'papi';
import papi from 'papi-backend';
import type { ExecutionToken } from 'node/models/execution-token.model';
import type IDataProviderEngine from 'shared/models/data-provider-engine.model';
import { UnsubscriberAsync } from 'shared/utils/papi-util';
Expand Down
7 changes: 6 additions & 1 deletion extensions/vite/vite.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ export const webViewTempDir = 'temp-vite';
export const webViewTempGlob = `**/${webViewTempDir}/*.web-view.js`;

/** Modules that Paranext supplies so extensions can use them easily */
export const paranextProvidedModules = ['react', 'react-dom/client', 'papi'];
export const paranextProvidedModules = [
'react',
'react-dom/client',
'papi-frontend',
'papi-backend',
];

/**
* Gets a file extension based on the moduleFormat input.
Expand Down
4 changes: 2 additions & 2 deletions lib/papi-dts/edit-papi-d-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ let papiDTS = fs.readFileSync(PAPI_DTS_PATH, 'utf8');

// Rename module 'shared/services/papi.service' to 'papi' so extensions can import just 'papi'
papiDTS = papiDTS
.replaceAll("'renderer/services/papi-renderer.service'", "'papi'")
.replaceAll("'extension-host/services/papi-extension-host.service'", "'papi'");
.replaceAll("'renderer/services/papi-frontend.service'", "'papi-frontend'")
.replaceAll("'extension-host/services/papi-backend.service'", "'papi-backend'");

// Remove all the @ from the @imports except @mui/material - not sure why these show up
// as they are all defined other than the css files and external modules
Expand Down
6 changes: 3 additions & 3 deletions lib/papi-dts/papi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ declare module 'shared/services/network-object.service' {
id: string,
createLocalObjectToProxy?: LocalObjectToProxyCreator<T> | undefined,
) => Promise<NetworkObject<T> | undefined>;
set: <T_1 extends NetworkableObject<object>>(
set: <T_1 extends NetworkableObject>(
id: string,
objectToShare: T_1,
) => Promise<DisposableNetworkObject<T_1>>;
Expand Down Expand Up @@ -2357,7 +2357,7 @@ declare module 'renderer/hooks/papi-hooks/index' {
export default papiHooks;
export type PapiHooks = typeof papiHooks;
}
declare module 'papi' {
declare module 'papi-frontend' {
const papi: {
react: {
context: {
Expand Down Expand Up @@ -2675,7 +2675,7 @@ declare module 'extension-host/services/extension-storage.service' {
export default extensionStorageService;
export type ExtensionStorageService = typeof extensionStorageService;
}
declare module 'papi' {
declare module 'papi-backend' {
const papi: {
storage: {
readTextFileFromInstallDirectory: (
Expand Down
4 changes: 2 additions & 2 deletions lib/papi-dts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"typeRoots": ["../node_modules/@types", "../extensions/dist", "../src/@types"]
},
"files": [
"../../src/renderer/services/papi-renderer.service.ts",
"../../src/extension-host/services/papi-extension-host.service.ts",
"../../src/renderer/services/papi-frontend.service.ts",
"../../src/extension-host/services/papi-backend.service.ts",
"../../src/extension-host/extension-types/extension.interface.ts"
]
}
2 changes: 1 addition & 1 deletion src/extension-host/extension-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isClient } from '@shared/utils/internal-util';
import * as networkService from '@shared/services/network.service';
import { CommandHandler } from '@shared/utils/papi-util';
import * as ExtensionService from '@extension-host/services/extension.service';
import papi from '@extension-host/services/papi-extension-host.service';
import papi from '@extension-host/services/papi-backend.service';
import logger from '@shared/services/logger.service';
import networkObjectService from '@shared/services/network-object.service';
import dataProviderService from '@shared/services/data-provider.service';
Expand Down
4 changes: 2 additions & 2 deletions src/extension-host/services/extension.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
getCommandLineArgumentsGroup,
} from '@node/utils/command-line.util';
import { setExtensionUris } from '@extension-host/services/extension-storage.service';
import papi from '@extension-host/services/papi-extension-host.service';
import papi from '@extension-host/services/papi-backend.service';
import executionTokenService from '@node/services/execution-token.service';
import { ExecutionActivationContext } from '@extension-host/extension-types/extension-activation-context.model';

Expand Down Expand Up @@ -194,7 +194,7 @@ const activateExtensions = async (extensions: ExtensionInfo[]): Promise<ActiveEx
const requireOriginal = Module.prototype.require;
Module.prototype.require = ((moduleName: string) => {
// Allow the extension to import papi
if (moduleName === 'papi') return papi;
if (moduleName === 'papi-backend') return papi;

// Figure out if we are doing the import for the extension file in activateExtension
const extensionFile = extensionsWithFiles.find(
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/global-this.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import React from 'react';
import { createRoot } from 'react-dom/client';
import { ProcessType } from '@shared/global-this.model';
import papi, { Papi } from '@renderer/services/papi-renderer.service';
import papi, { Papi } from '@renderer/services/papi-frontend.service';
import { getModuleSimilarApiMessage } from '@shared/utils/papi-util';

// #region webpack DefinePlugin types setup - these should be from the renderer webpack DefinePlugin
Expand All @@ -23,7 +23,7 @@ declare const webpackRenderer: {
* for packages that extensions import
*/
function webViewRequire(module: string) {
if (module === 'papi') return papi;
if (module === 'papi-frontend') return papi;
if (module === 'react') return React;
if (module === 'react-dom/client') return { createRoot };
// Tell the extension dev if there is an api similar to what they want to import
Expand Down

0 comments on commit 6b5a007

Please sign in to comment.