Sha256: cb33a9b4ec9db84a6717556292edd9f51dc4b3476c66895e6de822918cd3ec3d

Contents?: true

Size: 1.26 KB

Versions: 39

Compression:

Stored size: 1.26 KB

Contents

import setup from './setup_plugin.js'

export default setup('httpBundle', () => {
  return [
    {
      type: 'onResolve',
      filter: /^https?:\/\//,
      callback(args) {
        let queryParams, suffix
        if (args.path.includes('?')) {
          const [path, query] = args.path.split('?')
          queryParams = new URLSearchParams(query)
          suffix = `?${query}`
          args.path = path
        }

        if (queryParams?.has('bundle')) {
          return { path: args.path, namespace: 'httpBundle', suffix }
        } else {
          return { external: true }
        }
      }
    },

    // Intercept all import paths inside downloaded files and resolve them against the original URL.
    {
      type: 'onResolve',
      filter: /.*/,
      namespace: 'httpBundle',
      callback(args) {
        return {
          path: new URL(args.path, args.importer).toString(),
          namespace: 'httpBundle'
        }
      }
    },

    // Download and return the content.
    //
    // TODO: cache this!
    {
      type: 'onLoad',
      filter: /.*/,
      namespace: 'httpBundle',
      async callback(args) {
        const textResponse = await fetch(args.path)
        const contents = await textResponse.text()

        return { contents }
      }
    }
  ]
})

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
proscenium-0.6.0-arm64-darwin lib/proscenium/compilers/esbuild/http_bundle_plugin.js
proscenium-0.6.0-x86_64-darwin lib/proscenium/compilers/esbuild/http_bundle_plugin.js
proscenium-0.6.0-x86_64-linux lib/proscenium/compilers/esbuild/http_bundle_plugin.js
proscenium-0.5.1-arm64-darwin lib/proscenium/compilers/esbuild/http_bundle_plugin.js
proscenium-0.5.1-x86_64-darwin lib/proscenium/compilers/esbuild/http_bundle_plugin.js
proscenium-0.5.1-x86_64-linux lib/proscenium/compilers/esbuild/http_bundle_plugin.js
proscenium-0.5.0-arm64-darwin lib/proscenium/compilers/esbuild/http_bundle_plugin.js
proscenium-0.5.0-x86_64-darwin lib/proscenium/compilers/esbuild/http_bundle_plugin.js
proscenium-0.5.0-x86_64-linux lib/proscenium/compilers/esbuild/http_bundle_plugin.js
proscenium-0.4.2-arm64-darwin lib/proscenium/compilers/esbuild/http_bundle_plugin.js
proscenium-0.4.2-x86_64-darwin lib/proscenium/compilers/esbuild/http_bundle_plugin.js
proscenium-0.4.2-x86_64-linux lib/proscenium/compilers/esbuild/http_bundle_plugin.js
proscenium-0.4.1-arm64-darwin lib/proscenium/compilers/esbuild/http_bundle_plugin.js
proscenium-0.4.1-x86_64-darwin lib/proscenium/compilers/esbuild/http_bundle_plugin.js
proscenium-0.4.1-x86_64-linux lib/proscenium/compilers/esbuild/http_bundle_plugin.js
proscenium-0.4.0-arm64-darwin lib/proscenium/compilers/esbuild/http_bundle_plugin.js
proscenium-0.4.0-x86_64-darwin lib/proscenium/compilers/esbuild/http_bundle_plugin.js
proscenium-0.4.0-x86_64-linux lib/proscenium/compilers/esbuild/http_bundle_plugin.js
proscenium-0.3.0-arm64-darwin lib/proscenium/compilers/esbuild/http_bundle_plugin.js
proscenium-0.3.0-x86_64-darwin lib/proscenium/compilers/esbuild/http_bundle_plugin.js