mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-09-07 15:07:17 +00:00
refactor(player): centralize static dependencies
This commit is contained in:
committed by
Tobias Gesellchen
parent
c97e9958f6
commit
6752f71e67
@@ -1,6 +1,4 @@
|
||||
import { h, render } from '/app/static/lib/preact.module.js';
|
||||
import { useState, useEffect, useCallback } from '/app/static/lib/preact-hooks.module.js';
|
||||
import htm from '/app/static/lib/htm.module.js';
|
||||
import { h, htm, render, useCallback, useEffect, useState } from './dependencies.js';
|
||||
import { DeviceList } from './components/DeviceList.js';
|
||||
import { NowPlaying } from './components/NowPlaying.js';
|
||||
import { Controls } from './components/Controls.js';
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { h } from '/app/static/lib/preact.module.js';
|
||||
import { useState, useEffect } from '/app/static/lib/preact-hooks.module.js';
|
||||
import htm from '/app/static/lib/htm.module.js';
|
||||
import { h, htm, useEffect, useState } from '../dependencies.js';
|
||||
|
||||
const html = htm.bind(h);
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { h } from '/app/static/lib/preact.module.js';
|
||||
import { useState, useEffect } from '/app/static/lib/preact-hooks.module.js';
|
||||
import htm from '/app/static/lib/htm.module.js';
|
||||
import { h, htm, useEffect, useState } from '../dependencies.js';
|
||||
import { api } from '../api.js';
|
||||
|
||||
const html = htm.bind(h);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { h } from '/app/static/lib/preact.module.js';
|
||||
import { useState } from '/app/static/lib/preact-hooks.module.js';
|
||||
import htm from '/app/static/lib/htm.module.js';
|
||||
import { h, htm, useState } from '../dependencies.js';
|
||||
|
||||
const html = htm.bind(h);
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { h } from '/app/static/lib/preact.module.js';
|
||||
import { useState, useEffect } from '/app/static/lib/preact-hooks.module.js';
|
||||
import htm from '/app/static/lib/htm.module.js';
|
||||
import { h, htm, useEffect, useState } from '../dependencies.js';
|
||||
import { api } from '../api.js';
|
||||
|
||||
const html = htm.bind(h);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { h } from '/app/static/lib/preact.module.js';
|
||||
import { useState, useEffect, useRef } from '/app/static/lib/preact-hooks.module.js';
|
||||
import htm from '/app/static/lib/htm.module.js';
|
||||
import { h, htm, useEffect, useRef, useState } from '../dependencies.js';
|
||||
import { api } from '../api.js';
|
||||
|
||||
const html = htm.bind(h);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { h } from '/app/static/lib/preact.module.js';
|
||||
import { useState, useEffect } from '/app/static/lib/preact-hooks.module.js';
|
||||
import htm from '/app/static/lib/htm.module.js';
|
||||
import { h, htm, useEffect, useState } from '../dependencies.js';
|
||||
import { api } from '../api.js';
|
||||
|
||||
const html = htm.bind(h);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { h } from '/app/static/lib/preact.module.js';
|
||||
import { useState } from '/app/static/lib/preact-hooks.module.js';
|
||||
import htm from '/app/static/lib/htm.module.js';
|
||||
import { h, htm, useState } from '../dependencies.js';
|
||||
import { api } from '../api.js';
|
||||
|
||||
const html = htm.bind(h);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { h } from '/app/static/lib/preact.module.js';
|
||||
import { useState } from '/app/static/lib/preact-hooks.module.js';
|
||||
import htm from '/app/static/lib/htm.module.js';
|
||||
import { h, htm, useState } from '../dependencies.js';
|
||||
import { api } from '../api.js';
|
||||
|
||||
const html = htm.bind(h);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { h } from '/app/static/lib/preact.module.js';
|
||||
import { useState, useEffect } from '/app/static/lib/preact-hooks.module.js';
|
||||
import htm from '/app/static/lib/htm.module.js';
|
||||
import { h, htm, useEffect, useState } from '../dependencies.js';
|
||||
import { api } from '../api.js';
|
||||
|
||||
const html = htm.bind(h);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { h } from '/app/static/lib/preact.module.js';
|
||||
import htm from '/app/static/lib/htm.module.js';
|
||||
import { h, htm } from '../dependencies.js';
|
||||
import { api } from '../api.js';
|
||||
|
||||
const html = htm.bind(h);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { h } from '/app/static/lib/preact.module.js';
|
||||
import { useState } from '/app/static/lib/preact-hooks.module.js';
|
||||
import htm from '/app/static/lib/htm.module.js';
|
||||
import { h, htm, useState } from '../dependencies.js';
|
||||
import { api } from '../api.js';
|
||||
|
||||
const html = htm.bind(h);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { h } from '/app/static/lib/preact.module.js';
|
||||
import { useState, useEffect } from '/app/static/lib/preact-hooks.module.js';
|
||||
import htm from '/app/static/lib/htm.module.js';
|
||||
import { h, htm, useEffect, useState } from '../dependencies.js';
|
||||
import { api } from '../api.js';
|
||||
|
||||
const html = htm.bind(h);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { h } from '/app/static/lib/preact.module.js';
|
||||
import { useState, useEffect } from '/app/static/lib/preact-hooks.module.js';
|
||||
import htm from '/app/static/lib/htm.module.js';
|
||||
import { h, htm, useEffect, useState } from '../dependencies.js';
|
||||
import { api } from '../api.js';
|
||||
|
||||
const html = htm.bind(h);
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import { h, render } from '../lib/preact.module.js';
|
||||
import { useCallback, useEffect, useRef, useState } from '../lib/preact-hooks.module.js';
|
||||
import htm from '../lib/htm.module.js';
|
||||
|
||||
export { h, htm, render, useCallback, useEffect, useRef, useState };
|
||||
@@ -17,19 +17,28 @@ func TestStaticModulesDoNotRequireImportMaps(t *testing.T) {
|
||||
t.Fatal("index.html must not require import map support")
|
||||
}
|
||||
|
||||
dependencies := map[string]string{
|
||||
"/app/static/lib/preact.module.js": "static/lib/preact.module.js",
|
||||
"/app/static/lib/preact-hooks.module.js": "static/lib/preact-hooks.module.js",
|
||||
"/app/static/lib/htm.module.js": "static/lib/htm.module.js",
|
||||
const dependencyModulePath = "static/js/dependencies.js"
|
||||
dependencyModule, err := fs.ReadFile(StaticFS, dependencyModulePath)
|
||||
if err != nil {
|
||||
t.Fatalf("read dependency module: %v", err)
|
||||
}
|
||||
usedDependencies := make(map[string]bool, len(dependencies))
|
||||
for publicPath, embeddedPath := range dependencies {
|
||||
|
||||
dependencies := map[string]string{
|
||||
"../lib/preact.module.js": "static/lib/preact.module.js",
|
||||
"../lib/preact-hooks.module.js": "static/lib/preact-hooks.module.js",
|
||||
"../lib/htm.module.js": "static/lib/htm.module.js",
|
||||
}
|
||||
for modulePath, embeddedPath := range dependencies {
|
||||
if _, err := fs.Stat(StaticFS, embeddedPath); err != nil {
|
||||
t.Errorf("static dependency %q: %v", publicPath, err)
|
||||
t.Errorf("static dependency %q: %v", modulePath, err)
|
||||
}
|
||||
if !bytes.Contains(dependencyModule, []byte(modulePath)) {
|
||||
t.Errorf("dependency module does not import %q", modulePath)
|
||||
}
|
||||
}
|
||||
|
||||
bareDependency := regexp.MustCompile(`\bfrom\s*['"](?:preact(?:/hooks)?|htm)['"]`)
|
||||
directDependency := regexp.MustCompile(`\bfrom\s*['"][^'"]*lib/(?:preact(?:-hooks)?|htm)\.module\.js['"]`)
|
||||
err = fs.WalkDir(StaticFS, "static", func(path string, entry fs.DirEntry, walkErr error) error {
|
||||
if walkErr != nil {
|
||||
return walkErr
|
||||
@@ -45,10 +54,8 @@ func TestStaticModulesDoNotRequireImportMaps(t *testing.T) {
|
||||
if bareDependency.Match(source) {
|
||||
t.Errorf("%s contains a bare dependency import", path)
|
||||
}
|
||||
for publicPath := range dependencies {
|
||||
if bytes.Contains(source, []byte(publicPath)) {
|
||||
usedDependencies[publicPath] = true
|
||||
}
|
||||
if path != dependencyModulePath && strings.HasPrefix(path, "static/js/") && directDependency.Match(source) {
|
||||
t.Errorf("%s bypasses %s", path, dependencyModulePath)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -56,10 +63,4 @@ func TestStaticModulesDoNotRequireImportMaps(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("walk JavaScript modules: %v", err)
|
||||
}
|
||||
|
||||
for publicPath := range dependencies {
|
||||
if !usedDependencies[publicPath] {
|
||||
t.Errorf("static dependency %q is not imported", publicPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user