Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cf-worker): Add asset manifest to CF Service Worker #464

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/redirects.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FABRuntime } from '@fab/core'
import { FABRuntime } from '@dev-spendesk/fab-core'

const redirects = {
'/kb/plugins': '/plugins/introduction',
Expand Down
2 changes: 1 addition & 1 deletion docs/wip/blog-aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
FabPluginRuntime,
PluginMetadata,
FabSettings,
} from '@fab/core'
} from '@dev-spendesk/fab-core'

export const build: FabBuildStep = async (args: PluginArgs, proto_fab: ProtoFab) => {
const plugin_metadata: PluginMetadataContent = {}
Expand Down
2 changes: 1 addition & 1 deletion docs/wip/redirect-old-blog-urls.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// server/redirect-old-blog-urls/runtime.js

import { Runtime } from '@fab/core/runtime'
import { Runtime } from '@dev-spendesk/fab-core/runtime'

// We register a handler to match the old posts
Runtime.on('/posts/:id', async (matches, { request, settings, url }) => {
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"packages": ["packages/*"],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "1.0.0-rc.9"
"version": "1.0.0-rc.11"
}
8 changes: 4 additions & 4 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module.exports = {
'*.{js,css,json,md,ts}': ['prettier --write', 'git add'],
'*.ts': [
// For some reason, some IDE's auto-import feature will import '@fab/core/src'
// instead of '@fab/core'. This causes really weird TypeScript output.
// For some reason, some IDE's auto-import feature will import '@dev-spendesk/fab-core/src'
// instead of '@dev-spendesk/fab-core'. This causes really weird TypeScript output.
(files) =>
`bash -c "${[
"echo '=== Change @fab/core/src to @fab/core in the following files: ==='",
`grep -l @fab/core/src ${files.join(' ')}; test $? -eq 1`,
"echo '=== Change @dev-spendesk/fab-core/src to @dev-spendesk/fab-core in the following files: ==='",
`grep -l @dev-spendesk/fab-core/src ${files.join(' ')}; test $? -eq 1`,
].join(' && ')}"`,
],
}
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "fab-spec",
"name": "spendesk",
"version": "1.0.0-rc1",
"private": true,
"homepage": "https://github.com/fab-spec/fab",
"bugs": "https://github.com/fab-spec/fab/issues",
"repository": "fab-spec/fab",
"homepage": "https://github.com/spendesk/fab",
"bugs": "https://github.com/spendesk/fab/issues",
"repository": "spendesk/fab",
"workspaces": [
"packages/*"
],
Expand Down Expand Up @@ -57,6 +57,6 @@
"rimraf": "^3.0.0",
"ts-node": "^8",
"tsconfig-paths": "^3.9.0",
"typescript": "~3.7.2"
"typescript": "3.8.2"
}
}
20 changes: 10 additions & 10 deletions packages/_fab/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ https://www.npmjs.com/package/fab/v/0.5.3-original.
<!-- usage -->

```sh-session
$ npm install -g @fab/cli
$ npm install -g @dev-spendesk/fab-cli
$ fab COMMAND
running command...
$ fab (-v|--version|version)
@fab/cli/1.0.0-rc.9 darwin-x64 node-v15.5.1
@dev-spendesk/fab-cli/1.0.0-rc.11 linux-x64 node-v14.18.1
$ fab --help [COMMAND]
USAGE
$ fab COMMAND
Expand Down Expand Up @@ -75,7 +75,7 @@ EXAMPLES
$ fab build --watch dist --watch fab.config.json5
```

_See code: [lib/commands/build.js](https://github.com/fab-spec/fab/blob/v1.0.0-rc.9/lib/commands/build.js)_
_See code: [lib/commands/build.js](https://github.com/spendesk/fab/blob/v1.0.0-rc.11/lib/commands/build.js)_

## `fab deploy [FILE]`

Expand All @@ -97,8 +97,8 @@ OPTIONS

--assets-only Skip server deploy, just upload assets

--auto-install If you need dependent packages (e.g. @fab/deploy-*), install
them without prompting
--auto-install If you need dependent packages (e.g. @dev-spendesk/deploy-*),
install them without prompting

--env=env Override production settings with a different environment
defined in your FAB config file.
Expand All @@ -112,7 +112,7 @@ EXAMPLE
$ fab deploy fab.zip
```

_See code: [lib/commands/deploy.js](https://github.com/fab-spec/fab/blob/v1.0.0-rc.9/lib/commands/deploy.js)_
_See code: [lib/commands/deploy.js](https://github.com/spendesk/fab/blob/v1.0.0-rc.11/lib/commands/deploy.js)_

## `fab help [COMMAND]`

Expand Down Expand Up @@ -153,7 +153,7 @@ EXAMPLES
$ fab init --config=fab.config.json5
```

_See code: [lib/commands/init.js](https://github.com/fab-spec/fab/blob/v1.0.0-rc.9/lib/commands/init.js)_
_See code: [lib/commands/init.js](https://github.com/spendesk/fab/blob/v1.0.0-rc.11/lib/commands/init.js)_

## `fab package [FILE]`

Expand Down Expand Up @@ -182,7 +182,7 @@ EXAMPLE
$ fab package --target=aws-lambda-edge fab.zip
```

_See code: [lib/commands/package.js](https://github.com/fab-spec/fab/blob/v1.0.0-rc.9/lib/commands/package.js)_
_See code: [lib/commands/package.js](https://github.com/spendesk/fab/blob/v1.0.0-rc.11/lib/commands/package.js)_

## `fab serve [FILE]`

Expand All @@ -198,7 +198,7 @@ OPTIONS

-h, --help show CLI help

--auto-install If you need dependent packages (e.g. @fab/serve), install them without prompting
--auto-install If you need dependent packages (e.g. @dev-spendesk/serve), install them without prompting

--cert=cert SSL certificate to use

Expand All @@ -221,6 +221,6 @@ EXAMPLES
$ fab serve --env=staging fab.zip
```

_See code: [lib/commands/serve.js](https://github.com/fab-spec/fab/blob/v1.0.0-rc.9/lib/commands/serve.js)_
_See code: [lib/commands/serve.js](https://github.com/spendesk/fab/blob/v1.0.0-rc.11/lib/commands/serve.js)_

<!-- commandsstop -->
4 changes: 2 additions & 2 deletions packages/_fab/fab.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node

// This module defers to @fab/cli for all its work, we just use this namespace
// This module defers to @dev-spendesk/fab-cli for all its work, we just use this namespace
// so that `npx fab` does what we expect.
require('@fab/cli/bin/run')
require('@dev-spendesk/fab-cli/bin/run')
17 changes: 8 additions & 9 deletions packages/_fab/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "fab",
"version": "1.0.0-rc.9",
"description": "An alias for @fab/cli",
"name": "@dev-spendesk/fab",
"version": "1.0.0-rc.11",
"description": "An alias for @dev-spendesk/fab-cli",
"keywords": [
"fab"
],
"homepage": "https://github.com/fab-spec/fab#readme",
"homepage": "https://github.com/spendesk/fab#readme",
"bugs": {
"url": "https://github.com/fab-spec/fab/issues"
"url": "https://github.com/spendesk/fab/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/fab-spec/fab.git"
"url": "git+https://github.com/spendesk/fab.git"
},
"license": "MIT",
"author": "Glen Maddern",
Expand All @@ -27,7 +27,6 @@
"prepack": "cat PREAMBLE.md > README.md && cat ../cli/README.md >> README.md"
},
"dependencies": {
"@fab/cli": "1.0.0-rc.9"
},
"gitHead": "e0232b0579fb886d567c62ad793a128ff4ea34de"
"@dev-spendesk/fab-cli": "1.0.0-rc.11"
}
}
15 changes: 7 additions & 8 deletions packages/actions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fab/actions",
"version": "1.0.0-rc.9",
"name": "@dev-spendesk/fab-actions",
"version": "1.0.0-rc.11",
"private": false,
"description": "The guts of the FAB cli code, keeping the 'fab' package lean",
"keywords": [
Expand All @@ -10,8 +10,8 @@
"deploy",
"fab"
],
"homepage": "https://github.com/fab-spec/fab",
"repository": "fab-spec/fab",
"homepage": "https://github.com/spendesk/fab",
"repository": "spendesk/fab",
"license": "MIT",
"author": "Glen Maddern",
"files": [
Expand All @@ -31,8 +31,8 @@
"test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\""
},
"dependencies": {
"@fab/cli": "1.0.0-rc.9",
"@fab/core": "1.0.0-rc.9",
"@dev-spendesk/fab-cli": "1.0.0-rc.11",
"@dev-spendesk/fab-core": "1.0.0-rc.11",
"@rollup/plugin-alias": "^2.2.0",
"@rollup/plugin-commonjs": "^11.0.2",
"@rollup/plugin-inject": "^4.0.1",
Expand All @@ -58,6 +58,5 @@
},
"publishConfig": {
"access": "public"
},
"gitHead": "e0232b0579fb886d567c62ad793a128ff4ea34de"
}
}
4 changes: 2 additions & 2 deletions packages/actions/src/Builder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LoadedPlugin, RuntimePlugin, FabConfig, ProtoFab } from '@fab/core'
import { LoadedPlugin, RuntimePlugin, FabConfig, ProtoFab } from '@dev-spendesk/fab-core'
import { Compiler } from './Compiler'
import { Generator } from './Generator'
import { Typecheck } from './Typecheck'
Expand All @@ -8,7 +8,7 @@ import {
InvalidConfigError,
isRelative,
relativeToConfig,
} from '@fab/cli'
} from '@dev-spendesk/fab-cli'
import * as path from 'path'

const log = _log('Builder')
Expand Down
6 changes: 3 additions & 3 deletions packages/actions/src/Compiler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FabConfig, ProtoFab, RuntimePlugin } from '@fab/core'
import { _log, BuildFailedError } from '@fab/cli'
import { FabConfig, ProtoFab, RuntimePlugin } from '@dev-spendesk/fab-core'
import { _log, BuildFailedError } from '@dev-spendesk/fab-cli'
import { rollupCompile } from './rollup'

const log = _log(`Compiler`)
Expand All @@ -16,7 +16,7 @@ export class Compiler {
const warnings: string[] = []
const {
output: [output, ...chunks],
} = await rollupCompile(require.resolve('@fab/actions/esm/runtime'), {
} = await rollupCompile(require.resolve('@dev-spendesk/fab-actions/esm/runtime'), {
minify,
output: { format: 'umd', exports: 'named', name: '__fab' },
hypotheticals: {
Expand Down
36 changes: 23 additions & 13 deletions packages/actions/src/Deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {
FabDeployerExports,
FabSettings,
HOSTING_PROVIDERS,
} from '@fab/core'
} from '@dev-spendesk/fab-core'
import {
_log,
FabDeployError,
InvalidConfigError,
JSON5Config,
loadOrInstallModule,
loadOrInstallModules,
} from '@fab/cli'
} from '@dev-spendesk/fab-cli'

const log = _log('Deployer')

Expand All @@ -27,7 +27,7 @@ export default class Deployer {
package_dir: string,
server_host: DeployProviders | undefined,
assets_host: DeployProviders | undefined,
env: string | undefined,
envs: string[] | undefined,
assets_only: boolean,
assets_already_deployed_at: string | undefined,
auto_install: boolean
Expand All @@ -44,7 +44,7 @@ export default class Deployer {
`
)
}
const env_overrides = await this.getSettingsOverrides(config, env)
const env_overrides = await this.getSettingsOverrides(config, envs)

const { server_provider, assets_provider } = this.getProviders(
deploy,
Expand Down Expand Up @@ -92,22 +92,32 @@ export default class Deployer {
}

// TODO: this should be common somewhere
private static async getSettingsOverrides(config: JSON5Config, env?: string) {
if (!env) {
return {}
private static async getSettingsOverrides(
config: JSON5Config,
envs?: string[]
): Promise<Map<string, FabSettings>> {
const env_overrides = new Map()

if (!envs) {
return new Map([['production', {}]])
}
const overrides = config.data.settings?.[env]
if (!overrides) {
throw new InvalidConfigError(`No environment '${env}' found in ${config}!`)

for (const env of envs) {
const overrides = config.data.settings?.[env]
if (!overrides) {
throw new InvalidConfigError(`No environment '${env}' found in ${config}!`)
}
env_overrides.set(env, overrides)
}
return overrides

return env_overrides
}

private static async deployAssetsAndServer(
file_path: string,
package_dir: string,
deploy: DeployConfig,
env_overrides: FabSettings,
env_overrides: Map<string, FabSettings>,
assets_provider: DeployProviders,
server_provider: DeployProviders,
assets_only: boolean
Expand Down Expand Up @@ -191,7 +201,7 @@ export default class Deployer {
file_path: string,
package_dir: string,
config: FabSettings,
env_overrides: FabSettings,
env_overrides: Map<string, FabSettings>,
assets_url: string
) {
return await server_deployer.deployServer!(
Expand Down
6 changes: 3 additions & 3 deletions packages/actions/src/Generator.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ProtoFab } from '@fab/core'
import { ProtoFab } from '@dev-spendesk/fab-core'
import fs from 'fs-extra'
import path from 'path'
import util from 'util'
// @ts-ignore
import _zip from 'deterministic-zip'
import { _log, BuildFailedError } from '@fab/cli'
import { _log, BuildFailedError } from '@dev-spendesk/fab-cli'
import pretty from 'pretty-bytes'

const zip = util.promisify(_zip)
Expand All @@ -17,7 +17,7 @@ export class Generator {
if (invalid_reason) {
throw new BuildFailedError(`FAB is not ready for compilation.
${invalid_reason}
You might need to add @fab/plugin-rewire-assets to your 'build' config. See https://fab.dev/packages/rewire-assets for more information about what this module is and why it's needed.
You might need to add @dev-spendesk/fab-plugin-rewire-assets to your 'build' config. See https://fab.dev/packages/rewire-assets for more information about what this module is and why it's needed.
`)
}

Expand Down
6 changes: 3 additions & 3 deletions packages/actions/src/Packager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
FabPackagerExports,
HOSTING_PROVIDERS,
PackageFn,
} from '@fab/core'
import { _log, FabPackageError, loadModule } from '@fab/cli'
} from '@dev-spendesk/fab-core'
import { _log, FabPackageError, loadModule } from '@dev-spendesk/fab-cli'

const log = _log(`Packager`)

Expand Down Expand Up @@ -48,7 +48,7 @@ export default class Packager {
}

if (env) throw new Error('Not implemented ENV support yet')
const env_overrides = {}
const env_overrides = new Map()

const deploy_config = config.deploy![target] as ConfigTypes.Union
await packager.createPackage(
Expand Down
Loading