Skip to content

Commit

Permalink
fix(eleventy-plugin-styles): fixed support for less extension
Browse files Browse the repository at this point in the history
fix(eleventy-plugin-styles): changed state for purgeCss option
style(eleventy-plugin-cloudflare-image-resizing): formatted code (run linter)
style(eleventy-plugin-pwa-icons): formatted code (run linter)
style(eleventy-plugin-scripts): formatted code (run linter)
  • Loading branch information
Olezhka-web committed Sep 25, 2023
1 parent 6129e75 commit 0e06e2a
Show file tree
Hide file tree
Showing 16 changed files with 346 additions and 139 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
name: 'Test'

on: [ 'pull_request', 'push' ]
on: ['pull_request', 'push']

jobs:
test:

runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ 'ubuntu-latest', 'macos-latest', 'windows-latest' ]
node-version: [ '16.x' ]
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
node-version: ['16.x']

steps:
- name: 'Checkout repository'
Expand Down
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"debug": "^4.3.4",
"husky": "^7.0.4",
"jest": "^28.1.3",
"mock-fs": "^5.1.4",
"mock-fs": "^5.2.0",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"rollup": "^2.77.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/linker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const linker = <Options>({
sourcePath: resolve(baseDirectory, normalizedSourceUrl),
outputPath: resolve(outputDirectory, publicUrl.slice(1)),
originalUrl: sourceUrl,
isEdit: true
isEdit: true,
},
};
};
Expand Down
28 changes: 14 additions & 14 deletions packages/eleventy-plugin-cloudflare-image-resizing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = (config) => {
mode: 'img', // optional, default
directory: 'cloudflare-images', // optional, default
bypass: () => process.env.NODE_ENV !== 'production', // optional, default
cloudflareURL: () => zone + '/' + 'image' + originalURL // optional, usage example
cloudflareURL: () => zone + '/' + 'image' + originalURL, // optional, usage example
}),
);
};
Expand All @@ -36,18 +36,18 @@ module.exports = (config) => {
2. _url_ - shortcode outputs only final Cloudflare URL.
3. _attributes_ - shortcode outputs `<img>` ready to use attributes as the object.
3. _directory_ is the name of the directory under the _output_ which will contain referenced images.
Plugin copies images from source to the _output_ directory by itself. **Don't use the _addPassthroughCopy_ option
with images that are referenced by the plugin because you may end up with two copies.**
4. _bypass_ is a function that determines which image URL should be returned either from the Cloudflare service (for
the production environment, by default) or from the local directory (see directory option).
This function must return a boolean value. If true, a returned URL points to the Cloudflare service, otherwise -
the local directory.
Plugin copies images from source to the _output_ directory by itself. **Don't use the _addPassthroughCopy_ option
with images that are referenced by the plugin because you may end up with two copies.**
4. _bypass_ is a function that determines which image URL should be returned either from the Cloudflare service (for
the production environment, by default) or from the local directory (see directory option).
This function must return a boolean value. If true, a returned URL points to the Cloudflare service, otherwise -
the local directory.
5. _cloudflareURL_ is a function that allows you to customize your cloudflare URL.
cloudflareURL must have the following arguments:
* _zone_
* _domain_
* _options_ - cloudflare URL options like: format, quality, width, anim, etc.
* _originalURL_ - URL of your image
cloudflareURL must have the following arguments:
- _zone_
- _domain_
- _options_ - cloudflare URL options like: format, quality, width, anim, etc.
- _originalURL_ - URL of your image

### Shortcode has the following signature:

Expand All @@ -64,8 +64,8 @@ const result = cloudflareImage(url, options);
4. _sizes_ - list of all required image widths for the _srcset_ attribute. (_densities_ shouldn't be defined)
5. _attributes_ - a map of all additional `<img>` attributes.
6. _domain_ is the domain that acts as a place from where images are taken.
It may be omitted, and in that case, it will be implying that images are hosted on the current domain (which serves
the whole website).
It may be omitted, and in that case, it will be implying that images are hosted on the current domain (which serves
the whole website).

> _srcset_ attribute if defined in the _attributes_ is not used if _densities_ or _sizes_ is provided.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import {
} from '../src/build_cloudflare_image';

const mockDataCloudflare: Record<
'imageOptions' |
'imageOptionsWithCloudflareURL' |
'imageOptionsWithAttributes' |
'imageOptionsDifBypass' |
'imageOptionsWithPublicInternetUrl'|
'imageOptionsWithPublicInternetUrlDifBypass',
BuildCloudflareImageOptions> = {
| 'imageOptions'
| 'imageOptionsWithCloudflareURL'
| 'imageOptionsWithAttributes'
| 'imageOptionsDifBypass'
| 'imageOptionsWithPublicInternetUrl'
| 'imageOptionsWithPublicInternetUrlDifBypass',
BuildCloudflareImageOptions
> = {
imageOptions: {
normalizedZone: 'https://test.com',
normalizedDomain: 'https://test.com/',
Expand Down Expand Up @@ -53,7 +54,7 @@ const mockDataCloudflare: Record<
.join(',') +
URL_DELIMITER +
(domain ? domain + URL_DELIMITER : '') +
originalURL
originalURL,
},
imageOptionsWithAttributes: {
normalizedZone: '',
Expand Down Expand Up @@ -130,14 +131,16 @@ const mockDataCloudflare: Record<
toHTML: true,
disabled: false,
},
}
},
};

const getQuery = (url: string): string => url.match(/\?([^"]*)/)?.[1] || '';

describe('buildCloudflareImage', () => {
it('should return correct image url', () => {
const result = buildCloudflareImage(mockDataCloudflare.imageOptions) as string;
const result = buildCloudflareImage(
mockDataCloudflare.imageOptions,
) as string;
const query = getQuery(result);

expect(query).toHaveLength(11);
Expand All @@ -147,7 +150,9 @@ describe('buildCloudflareImage', () => {
});

it('should return correct image url (test with custom cloudflareURL)', () => {
const result = buildCloudflareImage(mockDataCloudflare.imageOptionsWithCloudflareURL);
const result = buildCloudflareImage(
mockDataCloudflare.imageOptionsWithCloudflareURL,
);

expect(result).toBe(
`<img src="http://localhost:8787/?image=https://test.com/cdn-cgi/image/anim=true,dpr=1,format=auto,quality=85/https://test.com/cloudflare-images/car.b62406a0fe1.jpg" />`,
Expand Down
2 changes: 1 addition & 1 deletion packages/eleventy-plugin-pwa-icons/src/update_manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const updateManifest = async ({
.then((data) =>
promises.writeFile(pathToOutputManifest, data, { encoding: 'utf-8' }),
);
}
};

export const handleManifest = once(
async (
Expand Down
3 changes: 2 additions & 1 deletion packages/eleventy-plugin-scripts/src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ export const bundle = async (
.then(
(validUrls) => {
const htmlWithScripts = validUrls.reduce(
(text, { input, output }) => text.replace(input, `${output}?${uid()}`),
(text, { input, output }) =>
text.replace(input, `${output}?${uid()}`),
html,
);

Expand Down
7 changes: 4 additions & 3 deletions packages/eleventy-plugin-styles/src/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ const extractCssFromLessResult = ({
*/
const compileLess: Compiler = (options: Less.Options) => (path: string) =>
tryExecute<Promise<CompilerResult>, Error>(() =>
pipe(
(path: string) => readFile(path, { encoding: 'utf8' }),
pipe((data: string) => render(data, options), extractCssFromLessResult),
pipe((path: string) =>
readFile(path, { encoding: 'utf8' }).then(
pipe((data: string) => render(data, options), extractCssFromLessResult),
),
)(path),
).extract((error) => (oops(error), resolve({ css: '', urls: [] })));

Expand Down
2 changes: 1 addition & 1 deletion packages/eleventy-plugin-styles/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/** Match stylesheet link and get URL of file from HTML. */
export const STYLESHEET_LINK_REGEXP =
/<link\s+[^>]*href=(?:'|")([^"]+\.(?:css|scss|sass))(?:'|")[^>]*>/g;
/<link\s+[^>]*href=(?:'|")([^"]+\.(?:css|scss|sass|less))(?:'|")[^>]*>/g;
4 changes: 2 additions & 2 deletions packages/eleventy-plugin-styles/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ definePluginName('Styles');
export const styles = (
config: Record<string, Function>,
{
sassOptions = {},
sassOptions = PluginState.Off,
lessOptions = PluginState.Off,
inputDirectory = join(DEFAULT_SOURCE_DIRECTORY, DEFAULT_STYLES_DIRECTORY),
cssnanoOptions = {},
addWatchTarget = true,
postcssPlugins = [],
criticalOptions = PluginState.Off,
purgeCSSOptions = {},
purgeCSSOptions = PluginState.Off,
publicDirectory = '',
}: StylesPluginOptions = {},
) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/eleventy-plugin-styles/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const normalize = async ({
url: fromUrl,
css,
html,
purgeCSSOptions = {},
purgeCSSOptions = PluginState.Off,
cssnanoOptions = {},
postcssPlugins = [],
}: NormalizeStepOptions) => {
Expand Down
Loading

0 comments on commit 0e06e2a

Please sign in to comment.