Skip to content

Commit

Permalink
Merge branch 'main' into chore/cache-buster-name-tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodBoyDigital committed Apr 29, 2024
2 parents 1b5bde4 + d00397d commit 7affd73
Show file tree
Hide file tree
Showing 173 changed files with 18,364 additions and 22,566 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ jobs:
- run: npm run lint
- run: npx nx affected --target=test:types --parallel=3
- uses: FedericoCarboni/setup-ffmpeg@v2
- run: npx nx affected --target=test --parallel=3 --ci
- run: npx nx affected --target=build --parallel=3
- run: npx nx affected --target=test --parallel=3 --ci
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@play-co:registry="https://npm.pkg.github.com/"
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
globals: {
'ts-jest': {
diagnostics: false,
}
},
testPathIgnorePatterns: ['/node_modules/', '/src/', '/dist/'],
testTimeout: 300000,
moduleNameMapper: {
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useWorkspaces": true,
"version": "0.8.0",
"version": "1.3.0",
"command": {
"publish": {
"graphType": "all"
Expand Down
28,175 changes: 9,611 additions & 18,564 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "assetpack",
"name": "@play-co/assetpack",
"private": true,
"license": "MIT",
"workspaces": [
Expand All @@ -10,10 +10,11 @@
"build:force": "nx run-many --target=build --all --parallel --skip-nx-cache",
"clean": "rimraf packages/*/{dist,.testInput,.testOutput,.assetpack}",
"lint": "eslint --cache packages shared --ext .js,.ts,.mjs --max-warnings 0",
"prerelease": "npm run lint && npm run test:force && npm run build:force",
"lint:fix": "npm run lint -- --fix",
"prepare": "husky install",
"prerelease": "npm run lint && npm run build:force",
"release": "lerna publish --no-private --exact --force-publish",
"release:fromPackage": "lerna publish from-package --no-private",
"prepare": "husky install",
"pretest": "npm run clean",
"test": "nx run-many --target=test --all --parallel",
"test:force": "nx run-many --target=test --all --parallel --skip-nx-cache",
Expand All @@ -30,6 +31,7 @@
"eslint --cache --fix --max-warnings 0"
]
},
"dependencies": {},
"devDependencies": {
"@nrwl/nx-cloud": "latest",
"@pixi/eslint-config": "^4.0.1",
Expand Down
44 changes: 44 additions & 0 deletions packages/cache-buster/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# @assetpack/plugin-cache-buster

AssetPack plugin for generating hashes and appending them to the file names.
Super useful for when assets change and they need to be re-downloaded.

Note that order matters with AssetPack plugins and its best to have this pipe transform happen at.

When combining this with `texturePacker` you add the `texturePackerCacheBuster` pipe right after
the `cacheBuster` pipe. `texturePackerCacheBuster` will ensure that the json files internanlly update their
asset names to accommodate the new file names.

## Example transform

```
|- assets
|- mySprite.png
|- myJson.json
```
transforms to:
```
|- assets
|- mySprite-dfs3e.png
|- myJson-aw3dsf.json
```
## Installation

```sh
npm install --save-dev @assetpack/plugin-cache-buster
```

## Basic Usage

```js
import { cacheBuster } from "@assetpack/plugin-cache-buster";

export default {
...
pipes: {
...
cacheBuster(),
},
};
```

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
...sharedConfig,
rootDir: './',
moduleNameMapper: {
'^@assetpack/plugin-(.*)$': '<rootDir>/../$1/src',
'^@assetpack/(.*)$': '<rootDir>/../$1/src',
'^@play-co/assetpack-plugin-(.*)$': '<rootDir>/../$1/src',
'^@play-co/assetpack-(.*)$': '<rootDir>/../$1/src',
},
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@assetpack/plugin-compress",
"version": "0.8.0",
"name": "@play-co/assetpack-plugin-cache-buster",
"version": "1.3.0",
"description": "",
"homepage": "https://github.com/pixijs/assetpack/tree/master/packages/compress/#readme",
"homepage": "https://github.com/pixijs/assetpack/tree/master/packages/cache-buster/#readme",
"bugs": "https://github.com/pixijs/assetpack/issues",
"repository": {
"url": "pixijs/assetpack",
"directory": "packages/compress"
"directory": "packages/cache-buster"
},
"license": "MIT",
"author": "Zyie",
Expand All @@ -29,14 +29,13 @@
"test:types": "tsc --noEmit"
},
"dependencies": {
"fs-extra": "^11.1.0",
"sharp": "^0.32.0"
"fs-extra": "^11.1.0"
},
"devDependencies": {
"@assetpack/core": "0.8.0"
"@play-co/assetpack-core": "1.3.0"
},
"peerDependencies": {
"@assetpack/core": ">=0.0.0"
"@play-co/assetpack-core": ">=0.0.0"
},
"engines": {
"node": ">=16.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { readFileSync } from 'fs';

import { createConfig } from '../../shared/rollup.config.mjs';

export default createConfig({
Expand Down
1 change: 1 addition & 0 deletions packages/cache-buster/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './cacheBuster';
49 changes: 49 additions & 0 deletions packages/cache-buster/test/cacheBuster.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { existsSync } from 'fs-extra';
import { assetPath, createFolder, getInputDir, getOutputDir } from '../../../shared/test';
import { cacheBuster } from '../src';
import { Asset, AssetPack, path } from '@play-co/assetpack-core';

const pkg = 'cache-buster';

describe('CacheBuster', () =>
{
it('should hash a file', async () =>
{
const testName = 'cache-buster';
const inputDir = getInputDir(pkg, testName);
const outputDir = getOutputDir(pkg, testName);

createFolder(
pkg,
{
name: testName,
files: [
{
name: 'ttf.ttf',
content: assetPath(pkg, 'Roboto-Regular.ttf'),
},
],
folders: [],
}
);

const assetpack = new AssetPack({
entry: inputDir,
output: outputDir,
cache: true,
pipes: [
cacheBuster()
]
});

await assetpack.run();

const originalPath = path.joinSafe('.testInput', testName, 'ttf.ttf');

const asset = new Asset({
path: originalPath,
});

expect(existsSync(path.joinSafe('.testOutput', testName, `ttf-${asset.hash}.ttf`))).toBe(true);
});
});
Binary file not shown.
Loading

0 comments on commit 7affd73

Please sign in to comment.