Skip to content

Inline cozy-sun-bear into heliotrope and switch pack to local source#3992

Draft
Copilot wants to merge 2 commits into
masterfrom
copilot/move-cozy-sun-bear-source
Draft

Inline cozy-sun-bear into heliotrope and switch pack to local source#3992
Copilot wants to merge 2 commits into
masterfrom
copilot/move-cozy-sun-bear-source

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 31, 2026

This PR moves the primary cozy-sun-bear implementation from a git URL dependency into heliotrope’s source tree so heliotrope builds and owns it directly. The change is scoped as a refactor: EPUB pack wiring is preserved, cozy-sun-bear-too remains untouched.

  • Source vendoring (new local module)

    • Added app/javascript/cozy-sun-bear/ with upstream JS source under src/** and styles under scss/**.
    • Added app/javascript/cozy-sun-bear/package.json with a minimal version shim for import { version } from '../package.json'.
  • Pack entrypoint migration to local code

    • Updated app/javascript/packs/cozy-sun-bear/cozy-sun-bear.js to import from local source.
    • Updated app/javascript/packs/cozy-sun-bear/cozy-sun-bear.css to import local SCSS instead of prebuilt dist CSS.
  • Dependency ownership shift to heliotrope

    • Removed cozy-sun-bear from root package.json.
    • Kept cozy-sun-bear-too unchanged.
    • Added runtime deps previously provided transitively by cozy-sun-bear: ajv, epubjs (cozy-sun-bear-2026), event-emitter, jszip, lodash, mustache, path-webpack.
    • Added Sass tooling required to build local SCSS (sass, sass-loader).
  • Webpack compatibility updates

    • Added resolve.alias.path = 'path-webpack' in config/webpack/environment.js.
    • Extended style handling to support .scss alongside .css.
// app/javascript/packs/cozy-sun-bear/cozy-sun-bear.js
import cozy from "../../cozy-sun-bear/src/cozy";
window.cozy = cozy;
Original prompt

Goal

Move the JavaScript source of mlibrary/cozy-sun-bear (currently consumed as a git-URL npm dependency) directly into heliotrope's own source tree, so heliotrope owns and builds it without needing the external repo. This is a pure refactor — no behaviour change, no new features. The EPUB reader must continue to work identically after this change.

Background

package.json currently has:

"cozy-sun-bear": "git+https://github.com/mlibrary/cozy-sun-bear.git",
"cozy-sun-bear-too": "git+https://github.com/mlibrary/cozy-sun-bear.git#too",

This PR only inlines the primary cozy-sun-bear (master branch). Leave cozy-sun-bear-too and its pack (app/javascript/packs/cozy-sun-bear-too/) completely untouched for now.

What to do

1. Copy the cozy-sun-bear source into heliotrope

Fetch all files from mlibrary/cozy-sun-bear (master branch) and place them under app/javascript/cozy-sun-bear/ in heliotrope, preserving the directory structure:

  • src/**app/javascript/cozy-sun-bear/src/**
  • scss/**app/javascript/cozy-sun-bear/scss/**

The files to copy (fetch each from https://github.com/mlibrary/cozy-sun-bear/blob/master/...):

src/ root:

  • src/cozy.js
  • src/epubjs.js
  • src/readium.js
  • src/screenfull.js

src/config/, src/control/, src/core/, src/dom/, src/epubjs/, src/geometry/, src/reader/, src/utils/ — fetch the directory listings from the GitHub API and copy all .js files found within each, preserving subdirectory structure.

scss/:

  • scss/cozy.scss
  • scss/_loader.scss
  • scss/_modals.scss
  • scss/_navigator.scss
  • scss/_open-iconic.scss

2. Fix the package.json import in src/cozy.js

The cozy-sun-bear src/cozy.js does:

import {version} from '../package.json';

After copying, ../package.json would resolve to heliotrope's root package.json, which is wrong. Fix this by creating a minimal app/javascript/cozy-sun-bear/package.json:

{ "version": "1.0.0" }

This satisfies the named import without touching heliotrope's real package.json.

3. Update the cozy-sun-bear pack entry point

app/javascript/packs/cozy-sun-bear/cozy-sun-bear.js currently:

import cozy from "cozy-sun-bear";
require("cozy-sun-bear/dist/cozy-sun-bear.css");
window.cozy = cozy;

Change to import from the local source. The CSS should come from the scss source, not a pre-compiled dist file:

import cozy from "../../cozy-sun-bear/src/cozy";
window.cozy = cozy;

app/javascript/packs/cozy-sun-bear/cozy-sun-bear.css currently:

@import "cozy-sun-bear/dist/cozy-sun-bear.css"

Change to import from the local scss source:

@import "../../cozy-sun-bear/scss/cozy";

4. Update package.json dependencies

In heliotrope's package.json:

  • Remove the "cozy-sun-bear" git dependency (the one pointing at master — do not remove cozy-sun-bear-too)
  • Add the runtime dependencies that cozy-sun-bear's own package.json lists (since heliotrope's webpack will now be building this code directly):
"ajv": "^8.0.0",
"epubjs": "git+https://github.com/mlibrary/epub.js.git#cozy-sun-bear-2026",
"event-emitter": "^0.3.5",
"jszip": "^3.10.0",
"lodash": "^4.18.1",
"mustache": "^4.2.0",
"path-webpack": "0.0.3"

Note: core-js is already present in heliotrope's package.json, so don't duplicate it.

5. Webpack alias for path

The cozy-sun-bear source uses import path from "path-webpack" via a webpack resolve.alias. Check heliotrope's webpack config (in config/webpack/) — if there is no existing alias for path → path-webpack, add one. Look for an environment.js or equivalent shakapacker config file in config/webpack/ and add:

environment.config.merge({
  resolve: {
    alias: {
      path: 'path-webpack'
    }
  }
});

6. Do NOT change

  • app/javascript/packs/cozy-sun-bear-too/ — leave entirely alone
  • The "cozy-sun-bear-too" entry in package.json — leave alone
  • All ERB views and Ruby code — no changes needed

Success criteria

  • yarn build (or the equivalent shakapacker compile command) completes without errors
  • No changes to any ERB templates or Ruby files
  • The cozy-sun-bear-too pack is untouched
  • The EPUB reader functionality is structurally identical (same window.cozy API surface)

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: I would like to consider how to unify the way mlibrary/heliotrope implements its ebook reader.

Some background:
mlibrary/cozy-sun-bear was originally written to use mlibrary/epub.js. Right now it uses the "cozy-sun-bear-2026" branch. Overall this is fairly stock epub.js, where the book is displayed in an iframe.

A few years later, online PDF reading was desired. The main goal was to have the interface (menus, buttons and "theme" colors) be largely the same between EPUB and PDF formats.
PDF.js was chosen...

This pull request was created from Copilot chat.

Copilot AI requested review from Copilot and removed request for Copilot May 31, 2026 20:59
Copilot AI requested review from Copilot and removed request for Copilot May 31, 2026 21:12
Copilot AI changed the title [WIP] Refactor to inline cozy-sun-bear source into heliotrope Inline cozy-sun-bear into heliotrope and switch pack to local source May 31, 2026
Copilot AI requested a review from conorom May 31, 2026 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants