Skip to content

Commit

Permalink
Remove next/asset (#6046)
Browse files Browse the repository at this point in the history
* Remove next/asset

Reasoning described in #5970

* Remove next/asset tests

* Bring back asset-page
  • Loading branch information
timneutkens committed Jan 14, 2019
1 parent 341fb99 commit 02ab732
Show file tree
Hide file tree
Showing 18 changed files with 5 additions and 158 deletions.
3 changes: 1 addition & 2 deletions examples/with-zones/home/pages/about.js
@@ -1,4 +1,3 @@
import asset from 'next/asset'
import Link from 'next/link'

export default () => (
Expand All @@ -9,6 +8,6 @@ export default () => (
<a>Go Back</a>
</Link>
</div>
<img width={200} src={asset('/zeit.png')} />
<img width={200} src='/static/zeit.png' />
</div>
)
3 changes: 1 addition & 2 deletions examples/with-zones/home/pages/index.js
@@ -1,5 +1,4 @@
import Link from 'next/link'
import asset from 'next/asset'
import dynamic from 'next/dynamic'

const Header = dynamic(import('../components/Header'))
Expand All @@ -18,6 +17,6 @@ export default () => (
<a>About us</a>
</Link>
</div>
<img width={200} src={asset('/nextjs.png')} />
<img width={200} src='/static/nextjs.png' />
</div>
)
1 change: 0 additions & 1 deletion packages/next-server/asset.js

This file was deleted.

15 changes: 0 additions & 15 deletions packages/next-server/lib/asset.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/next-server/package.json
Expand Up @@ -6,7 +6,6 @@
"files": [
"dist",
"index.js",
"asset.js",
"config.js",
"constants.js",
"dynamic.js",
Expand Down
2 changes: 0 additions & 2 deletions packages/next-server/server/next-server.ts
Expand Up @@ -11,7 +11,6 @@ import Router, {route, Route} from './router'
import { isInternalUrl, isBlockedPage } from './utils'
import loadConfig from 'next-server/next-config'
import {PHASE_PRODUCTION_SERVER, BUILD_ID_FILE, CLIENT_STATIC_FILES_PATH, CLIENT_STATIC_FILES_RUNTIME} from 'next-server/constants'
import * as asset from '../lib/asset'
import * as envConfig from '../lib/runtime-config'
import {loadComponents} from './load-components'

Expand Down Expand Up @@ -111,7 +110,6 @@ export default class Server {

public setAssetPrefix(prefix?: string) {
this.renderOpts.assetPrefix = prefix ? prefix.replace(/\/$/, '') : ''
asset.setAssetPrefix(this.renderOpts.assetPrefix)
}

// Backwards compatibility
Expand Down
1 change: 0 additions & 1 deletion packages/next/asset.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/next/build/babel/plugins/next-to-next-server.ts
Expand Up @@ -7,9 +7,6 @@ export default function NextToNextServer (): PluginObj {
visitor: {
ImportDeclaration (path: NodePath<ImportDeclaration>) {
const source = path.node.source.value
if (source === 'next/asset') {
path.node.source.value = 'next-server/asset'
}
if (source === 'next/dynamic') {
path.node.source.value = 'next-server/dynamic'
}
Expand Down
4 changes: 0 additions & 4 deletions packages/next/export/index.js
Expand Up @@ -7,7 +7,6 @@ import { resolve, join } from 'path'
import { existsSync, readFileSync } from 'fs'
import loadConfig from 'next-server/next-config'
import { PHASE_EXPORT, SERVER_DIRECTORY, PAGES_MANIFEST, CONFIG_FILE, BUILD_ID_FILE, CLIENT_STATIC_FILES_PATH } from 'next-server/constants'
import { setAssetPrefix } from 'next-server/asset'
import * as envConfig from 'next-server/config'
import createProgress from 'tty-aware-progress'

Expand Down Expand Up @@ -104,9 +103,6 @@ export default async function (dir, options, configuration) {
publicRuntimeConfig
})

// set the assetPrefix to use for 'next/asset'
setAssetPrefix(renderOpts.assetPrefix)

// We need this for server rendering the Link component.
global.__NEXT_DATA__ = {
nextExport: true
Expand Down
1 change: 0 additions & 1 deletion packages/next/package.json
Expand Up @@ -10,7 +10,6 @@
"files": [
"dist",
"app.js",
"asset.js",
"babel.js",
"client.js",
"config.js",
Expand Down
10 changes: 0 additions & 10 deletions test/integration/basic/pages/using-asset/asset.js

This file was deleted.

9 changes: 0 additions & 9 deletions test/integration/basic/pages/using-asset/index.js

This file was deleted.

57 changes: 0 additions & 57 deletions test/integration/basic/test/asset.js

This file was deleted.

2 changes: 0 additions & 2 deletions test/integration/basic/test/index.test.js
Expand Up @@ -15,7 +15,6 @@ import clientNavigation from './client-navigation'
import hmr from './hmr'
import errorRecovery from './error-recovery'
import dynamic from './dynamic'
import asset from './asset'
import processEnv from './process-env'

const context = {}
Expand Down Expand Up @@ -72,6 +71,5 @@ describe('Basic Features', () => {
dynamic(context, (p, q) => renderViaHTTP(context.appPort, p, q))
hmr(context, (p, q) => renderViaHTTP(context.appPort, p, q))
errorRecovery(context, (p, q) => renderViaHTTP(context.appPort, p, q))
asset(context)
processEnv(context)
})
4 changes: 1 addition & 3 deletions test/integration/custom-server/pages/asset.js
@@ -1,7 +1,5 @@
import asset from 'next/asset'

export default () => (
<div id='asset-page'>
<img src={asset('/myimage.png')} />
asset page
</div>
)
34 changes: 2 additions & 32 deletions test/integration/custom-server/test/index.test.js
Expand Up @@ -3,14 +3,12 @@
import { join } from 'path'
import getPort from 'get-port'
import clone from 'clone'
import cheerio from 'cheerio'
import {
initNextServerScript,
killApp,
renderViaHTTP,
fetchViaHTTP
} from 'next-test-utils'
import webdriver from 'next-webdriver'

const appDir = join(__dirname, '../')
let appPort
Expand Down Expand Up @@ -50,8 +48,8 @@ describe('Custom Server', () => {
})

it('should handle null assetPrefix accordingly', async () => {
const $normal = cheerio.load(await renderViaHTTP(appPort, '/asset?setEmptyAssetPrefix=1'))
expect($normal('img').attr('src')).toBe('/static/myimage.png')
const normalUsage = await renderViaHTTP(appPort, '/asset?setEmptyAssetPrefix=1')
expect(normalUsage).toMatch(/"\/_next/)
})

it('should set the assetPrefix to a given request', async () => {
Expand All @@ -65,34 +63,6 @@ describe('Custom Server', () => {
expect(dynamicUsage).toMatch(/127\.0\.0\.1/)
}
})

it('should support next/asset in server side', async () => {
const $normal = cheerio.load(await renderViaHTTP(appPort, '/asset'))
expect($normal('img').attr('src')).toBe('/static/myimage.png')

const $dynamic = cheerio.load(await renderViaHTTP(appPort, '/asset?setAssetPrefix=1'))
expect($dynamic('img').attr('src')).toBe(`http://127.0.0.1:${context.appPort}/static/myimage.png`)
})

it('should support next/asset in client side', async () => {
const browser = await webdriver(context.appPort, '/')
await browser
.elementByCss('#go-asset').click()
.waitForElementByCss('#asset-page')

expect(await browser.elementByCss('img').getAttribute('src'))
.toBe(`http://localhost:${context.appPort}/static/myimage.png`)
browser.close()

const browser2 = await webdriver(context.appPort, '/?setAssetPrefix=1')
await browser2
.elementByCss('#go-asset').click()
.waitForElementByCss('#asset-page')

expect(await browser2.elementByCss('img').getAttribute('src'))
.toBe(`http://127.0.0.1:${context.appPort}/static/myimage.png`)
browser2.close()
})
})

describe('with generateEtags enabled', () => {
Expand Down
7 changes: 0 additions & 7 deletions test/integration/export/pages/asset.js

This file was deleted.

6 changes: 0 additions & 6 deletions test/integration/export/test/ssr.js
Expand Up @@ -43,12 +43,6 @@ export default function (context) {
expect(html).toMatch(/Query is: {}/)
})

it('should handle next/asset properly', async () => {
const html = await renderViaHTTP(context.port, '/asset')
const $ = cheerio.load(html)
expect($('img').attr('src')).toBe('/static/myimage.png')
})

it('should render _error on 404', async () => {
const html = await renderViaHTTP(context.port, '/404')
expect(html).toMatch(/404/)
Expand Down

0 comments on commit 02ab732

Please sign in to comment.