Skip to content

Commit

Permalink
fix: rework internal plugin structure (#178)
Browse files Browse the repository at this point in the history
* rework internal plugin structure

* update workflow

* fix tests
  • Loading branch information
KonnorRogers authored Jan 27, 2022
1 parent 17e3df0 commit e86f419
Show file tree
Hide file tree
Showing 42 changed files with 56 additions and 111 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ jobs:
pnpm-lock.yaml
plugins/pnpm-lock.yaml
- name: Install via yarn
- name: Install via pnpm
run: |
pnpm install
cd plugins && pnpm install
- name: lint, and test
run: |
pnpm lint
Expand Down Expand Up @@ -72,13 +71,9 @@ jobs:
pnpm-lock.yaml
plugins/pnpm-lock.yaml
- name: Install via yarn
run: |
- name: Install via yarn
- name: Install via pnpm
run: |
pnpm install
cd plugins && pnpm install && cd -
pnpm build
cd test/rails/dummy
pnpm install
Expand Down
19 changes: 8 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
"require": "./dist/mrujs.js"
},
"./plugins": {
"browser": "./plugins/dist/mrujs.module.js",
"umd": "./plugins/dist/mrujs.umd.js",
"import": "./plugins/dist/mrujs.module.js",
"require": "./plugins/dist/mrujs.js"
"browser": "./dist/plugins.module.js",
"umd": "./dist/plugins.umd.js",
"import": "./dist/plugins.module.js",
"require": "./dist/plugins.js"
}
},
"types": "dist/types/src/index.d.ts",
Expand All @@ -35,10 +35,7 @@
},
"files": [
"src",
"dist",
"plugins/src",
"plugins/dist",
"plugins/package.json"
"dist"
],
"sideEffects": [
"./src/index.ts",
Expand All @@ -48,9 +45,9 @@
"url": "https://github.com/paramagicdev/mrujs/issues"
},
"scripts": {
"clean": "rm -rf dist plugins/dist",
"lint": "ts-standard plugins/ src/ test/js",
"fix": "ts-standard plugins/ src/ test/js --fix",
"clean": "rm -rf dist",
"lint": "ts-standard src/ test/js",
"fix": "ts-standard src/ test/js --fix",
"test": "web-test-runner",
"test:ci": "pnpm lint && pnpm build && web-test-runner",
"test:watch": "web-test-runner --watch",
Expand Down
23 changes: 0 additions & 23 deletions plugins/package.json

This file was deleted.

13 changes: 0 additions & 13 deletions plugins/yarn.lock

This file was deleted.

30 changes: 14 additions & 16 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,24 @@ export default [

// Plugins
{
external: ["SparkMD5"],
input: "plugins/src/index.ts",
input: "src/plugins/index.ts",
output: [{
file: "plugins/dist/mrujs.module.js",
file: "dist/plugins.module.js",
format: "es",
sourcemap: true,
}],
plugins: basePlugins("./tsconfig-plugins.json")
plugins: basePlugins()
},
{
input: "plugins/src/index.ts",
input: "src/plugins/index.ts",
output: [{
name: "mrujs",
file: "plugins/dist/mrujs.umd.js",
name: "mrujsPlugins",
file: "dist/plugins.umd.js",
format: "umd",
sourcemap: true,
exports: "named",
}],
plugins: basePlugins("./tsconfig-plugins.json")
plugins: basePlugins()
},

// Compressed
Expand Down Expand Up @@ -103,24 +102,23 @@ export default [

// Plugins
{
external: ["SparkMD5"],
input: "plugins/src/index.ts",
input: "src/plugins/index.ts",
output: [{
file: "plugins/dist/mrujs.module.min.js",
file: "dist/plugins.module.min.js",
format: "es",
sourcemap: true,
}],
plugins: compressionPlugins("./tsconfig-plugins.json")
plugins: compressionPlugins()
},
{
input: "plugins/src/index.ts",
input: "src/plugins/index.ts",
output: [{
name: "mrujs",
file: "plugins/dist/mrujs.umd.min.js",
name: "mrujsPlugins",
file: "dist/plugins.umd.min.js",
format: "umd",
sourcemap: true,
exports: "named",
}],
plugins: compressionPlugins("./tsconfig-plugins.json")
plugins: compressionPlugins()
},
]
2 changes: 1 addition & 1 deletion src/addedNodesObserver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MrujsPluginInterface } from '../types'
import { MrujsPluginInterface } from './types'

/**
* Mutation observer for added nodes.
Expand Down
2 changes: 1 addition & 1 deletion src/clickHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addListeners, attachObserverCallback, removeListeners } from './utils/dom'
import { preventInsignificantClick } from './utils/misc'
import { EventQueryInterface, MrujsPluginInterface } from '../types'
import { EventQueryInterface, MrujsPluginInterface } from './types'

export function ClickHandler (): MrujsPluginInterface {
const callbacks = [preventInsignificantClick] as EventListener[]
Expand Down
2 changes: 1 addition & 1 deletion src/confirm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { dispatch, stopEverything } from './utils/events'
import { addListeners, removeListeners, attachObserverCallback } from './utils/dom'
import { EventQueryInterface, MrujsPluginInterface } from '../types'
import { EventQueryInterface, MrujsPluginInterface } from './types'

export function Confirm (): MrujsPluginInterface {
const callbacks = [handleConfirm] as EventListener[]
Expand Down
2 changes: 1 addition & 1 deletion src/csrf.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// https://github.com/rails/rails/blob/main/actionview/app/assets/javascripts/rails-ujs/utils/csrf.coffee
import { getCookieValue, getMetaContent } from './utils/misc'
import { MrujsPluginInterface } from '../types'
import { MrujsPluginInterface } from './types'
import { $ } from './utils/dom'

export function Csrf (): MrujsPluginInterface {
Expand Down
2 changes: 1 addition & 1 deletion src/disabledElementChecker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MrujsPluginInterface, EventQueryInterface } from '../types'
import { MrujsPluginInterface, EventQueryInterface } from './types'
import { addListeners, removeListeners, attachObserverCallback } from './utils/dom'
import { stopEverything } from './utils/events'

Expand Down
2 changes: 1 addition & 1 deletion src/elementDisabler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MrujsPluginInterface, EventQueryInterface, Submitter } from '../types'
import { MrujsPluginInterface, EventQueryInterface, Submitter } from './types'
import { attachObserverCallback, addListeners, removeListeners, formElements, matches } from './utils/dom'
import { stopEverything } from './utils/events'

Expand Down
2 changes: 1 addition & 1 deletion src/elementEnabler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { attachObserverCallback, matches, addListeners, removeListeners, formElements } from './utils/dom'
import { stopEverything, AJAX_EVENTS } from './utils/events'
import { SelectorType, EventQueryInterface, MrujsPluginInterface } from '../types'
import { SelectorType, EventQueryInterface, MrujsPluginInterface } from './types'

export function ElementEnabler (): MrujsPluginInterface {
const callbacks = [enableElement] as EventListener[]
Expand Down
2 changes: 1 addition & 1 deletion src/formSubmission.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { buildFormElementFormData, formEnctypeFromString, FormEncType, FormEncTypes, urlEncodeFormData } from './utils/form'
import { findResponseTypeHeader } from './utils/headers'
import { FetchRequestInterface, Submitter } from '../types'
import { FetchRequestInterface, Submitter } from './types'
import { FetchRequest } from './http/fetchRequest'
import { isGetRequest, expandUrl } from './utils/url'

Expand Down
2 changes: 1 addition & 1 deletion src/formSubmitDispatcher.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AJAX_EVENTS, dispatch } from './utils/events'
import { findSubmitter } from './submitFinder'
import { FetchResponse } from './http/fetchResponse'
import { MrujsPluginInterface, AddOrRemoveListeners, AjaxEventDetail, ExtendedSubmitEvent } from '../types'
import { MrujsPluginInterface, AddOrRemoveListeners, AjaxEventDetail, ExtendedSubmitEvent } from './types'
import { FormSubmission } from './formSubmission'
import { disableElement } from './elementDisabler'

Expand Down
2 changes: 1 addition & 1 deletion src/http/fetchRequest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AJAX_EVENTS, dispatch, stopEverything } from '../utils/events'
import { isGetRequest, mergeHeaders, expandUrl } from '../utils/url'
import { CSRFProtection } from '../csrf'
import { RequestInfo, FetchRequestBody, FetchRequestInterface, Locateable } from '../../types'
import { RequestInfo, FetchRequestBody, FetchRequestInterface, Locateable } from '../types'

/**
* Fetch Request is essentially an "proxy" class meant to wrap a standard Request
Expand Down
2 changes: 1 addition & 1 deletion src/http/fetchResponse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expandUrl } from '../utils/url'
import { FetchResponseInterface } from '../../types'
import { FetchResponseInterface } from '../types'

// Shamelessly stolen from Turbo.
// https://github.com/hotwired/turbo/blob/main/src/http/fetch_response.ts
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import './polyfills'

import { Mrujs } from './mrujs'
import { Adapter, MrujsInterface } from '../types'
import { Adapter, MrujsInterface } from './types'

// This is required for typescript checking in tests
declare global {
Expand Down
2 changes: 1 addition & 1 deletion src/method.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AJAX_EVENTS, dispatch } from './utils/events'
import { EventQueryInterface, MrujsPluginInterface } from '../types'
import { EventQueryInterface, MrujsPluginInterface } from './types'
import { addListeners, removeListeners, attachObserverCallback } from './utils/dom'
import { MethodSubmission } from './methodSubmission'

Expand Down
2 changes: 1 addition & 1 deletion src/methodSubmission.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { urlEncodeFormData } from './utils/form'
import { findResponseTypeHeader } from './utils/headers'
import { FetchRequest } from './http/fetchRequest'
import { FetchRequestInterface } from '../types'
import { FetchRequestInterface } from './types'
import { expandUrl, isGetRequest } from './utils/url'

export interface MethodSubmissionInterface {
Expand Down
2 changes: 1 addition & 1 deletion src/mrujs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
Locateable,
ExtendedRequestInit,
MrujsInterface
} from '../types'
} from './types'

export function Mrujs (obj: Partial<MrujsInterface> = {}): MrujsInterface {
obj.connected = false
Expand Down
2 changes: 1 addition & 1 deletion src/navigationAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Adapter, MrujsPluginInterface, SnapshotCacheInterface,
Locateable, FetchRequestInterface, FetchResponseInterface,
VisitAction
} from '../types'
} from './types'

const ALLOWABLE_ACTIONS = [
'advance',
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion plugins/src/index.ts → src/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Adapter, MrujsInterface } from '../../types'
import { Adapter, MrujsInterface } from '../types'

declare global {
interface Window {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion plugins/src/mrujs.ts → src/plugins/mrujs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Adapter, MrujsInterface } from '../../types'
import { Adapter, MrujsInterface } from '../types'

declare global {
interface Window {
Expand Down
2 changes: 1 addition & 1 deletion plugins/src/mrujsTurbo.ts → src/plugins/mrujsTurbo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MrujsPluginInterface } from '../../types'
import { MrujsPluginInterface } from '../types'

export function MrujsTurbo (): MrujsPluginInterface {
return {
Expand Down
2 changes: 1 addition & 1 deletion plugins/src/shoelace.ts → src/plugins/shoelace.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MrujsPluginInterface, MrujsInterface } from '../../types'
import { MrujsPluginInterface, MrujsInterface } from '../types'

export function Shoelace (): MrujsPluginInterface {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/remoteWatcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SelectorType, MrujsPluginInterface } from '../types'
import { SelectorType, MrujsPluginInterface } from './types'
import { $, matches } from './utils/dom'

export function RemoteWatcher (): MrujsPluginInterface {
Expand Down
2 changes: 1 addition & 1 deletion src/submitFinder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExtendedSubmitEvent, Submitter } from '../types'
import { ExtendedSubmitEvent, Submitter } from './types'

export function findSubmitter (event: ExtendedSubmitEvent): Submitter {
// Not supported by webkit
Expand Down
1 change: 0 additions & 1 deletion types.ts → src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,3 @@ export interface ExtendedSubmitEvent extends CustomEvent {
submitter?: Submitter
}
}

2 changes: 1 addition & 1 deletion src/utils/dom.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is copied from:
// https://github.com/rails/rails/blob/main/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee
import { EventQueryInterface, QuerySelectorInterface, SelectorType } from '../../types'
import { EventQueryInterface, QuerySelectorInterface, SelectorType } from '../types'

export function toArray<T> (value: any): T[] {
if (Array.isArray(value)) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/events.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { matches } from './dom'
import { SelectorType } from '../../types'
import { SelectorType } from '../types'

export const EVENT_DEFAULTS = {
bubbles: true,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/form.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Submitter } from '../../types'
import { Submitter } from '../types'

export function buildFormElementFormData (element: HTMLFormElement, submitter?: Submitter): FormData {
const formData = new FormData(element)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/headers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MimeTypeInterface } from '../../types'
import { MimeTypeInterface } from '../types'

export const BASE_ACCEPT_HEADERS: MimeTypeInterface = {
'*': '*/*',
Expand Down
2 changes: 1 addition & 1 deletion src/utils/url.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Locateable } from '../../types'
import { Locateable } from '../types'

export function expandUrl (locateable: Locateable): URL {
return new URL(locateable.toString(), document.baseURI)
Expand Down
2 changes: 1 addition & 1 deletion test/js/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This is a base test for the plugin interface.
import { MrujsPluginInterface } from '../../types'
import { MrujsPluginInterface } from '../../src/types'
import { assert } from '@esm-bundle/chai'
import { spy } from 'sinon'

Expand Down
2 changes: 1 addition & 1 deletion test/js/plugins/cableCar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { assert } from '@esm-bundle/chai'
import CableReady from 'cable_ready'

import mrujs from '../../../src'
import { CableCar } from '../../../plugins'
import { CableCar } from '../../../src/plugins'

const cableCar = new CableCar(CableReady)

Expand Down
2 changes: 1 addition & 1 deletion test/js/plugins/cableCarMimeType.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assert } from '@esm-bundle/chai'
import CableReady from 'cable_ready'
import mrujs from '../../../src'
import { CableCar } from '../../../plugins'
import { CableCar } from '../../../src/plugins'

describe('CableCar with custom config', () => {
it('should allow custom mimetypes', () => {
Expand Down
Loading

0 comments on commit e86f419

Please sign in to comment.